#calling GET, POST, DELETE, and PUT request in one next.js api file
27 messages · Page 1 of 1 (latest)
hiii. I've already done that. I only can do GET and DELETE. methods for POST and PUT haven't implemented yet.
you can read the guide here https://beta.nextjs.org/docs/routing/route-handlers#dynamic-route-handlers
if you want to POST or UPDATE. you can use GET for a while and pass the data in url params
POST and PUT work well
they were implemented at the same time as GET and DELETE
what do you mean?
yes. but you can't send data in request.body
await request.json()
you're simply using it wrong
please do not spread misinformation
If by that you mean, having one API file with all your calls I think you'd have to make calls to that api based on some conditions
and I'm not sure it'd be great to have all your API calls in only one file
You can have all 4 HTTP request methods inside of one route.tsx file. Make sure to use await request.json() when trying to read the body in the relevant methods
then I guess he should make a switch
and have a special property in the body of the request
so he can define which is which
asks a super unclear question
refuses to elaborate
leaves
I still can’t understand what exactly OP is trying to do
I believe he wanted to write 4 calls into one file
Like
mycalls.ts
fetch1()
fetch2()
fetch3()
fetch4()
guys i'm trying to use the delete method, how do i get parameters from the url?
let's say my url looks like this /api/something/id, how do i get the id from it? do i have to use the url object?