Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update delete method in api crud operations #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions step11_route_handler/step01_crud/src/app/api/greetings/route.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,43 @@
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest) {
return NextResponse.json({
From: "Zia",
Message: "Greetings from Pakistan",
RequestType: "GET"
});
return NextResponse.json({
From: "Zia",
Message: "Greetings from Pakistan",
RequestType: "GET",
});
}

export async function POST(request: NextRequest) {
const req = await request.json();
if(req.name){
if (req.name) {
return NextResponse.json({
To: "Zia",
Message: "All well here",
RequestType: "POST"
RequestType: "POST",
});
}
else {
return new NextResponse('Please include your name in the POST request');
} else {
return new NextResponse("Please include your name in the POST request");
}
}

export async function PUT(request: NextRequest) {
const req = await request.json();
if(req.name){
if (req.name) {
return NextResponse.json({
To: "Zia",
Message: "This is a updated greeting",
RequestType: "PUT"
RequestType: "PUT",
});
}
else {
return new NextResponse('Please include your name in the PUT request');
} else {
return new NextResponse("Please include your name in the PUT request");
}
}

export async function DELETE(request: NextRequest) {
const req = await request.json();
if(req.name){
return NextResponse.json({
To: "Zia",
Message: "I have deleted the greetings",
RequestType: "DELETE"
});
}
else {
return new NextResponse('Please include your name in the DELETE request');
}
return NextResponse.json({
To: "Zia",
Message: "I have deleted the greetings",
RequestType: "DELETE",
});
}