Next.js Discord

Discord Forum

Send the data to the server in JSON but server receives empty object

Unanswered
Jersey Wooly posted this in #help-forum
Open in Discord
Jersey WoolyOP
i`m trying to send a delete request with a specific id, when i test with the thunderclient i can do the delete just fine, but when i try to send the request trough the front-end the server receives a empty object

const deleteItem = async (event: FormEvent) => {
    event.preventDefault()

    const JSONdata = JSON.stringify({ id: 1 })

    const endpoint = '/api/delete'

    console.log(JSONdata)
    const options = {
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSONdata,
    }

    await fetch(endpoint, options)
  }
  

8 Replies

Jersey WoolyOP
thanks! i`m using prisma to handle the database, how can i send a specifc id to the server?
i want to press the delete and send the requisition with the specifc id
You can use a path param (DELETE /items/123) or searchParams (DELETE /item?id=123)
Jersey WoolyOP
thanks! i`ll try that!
in a REST way you could have app/items/[id]/route.ts with a DELETE, POST, etc handlers.