Skip to content
Advertisement

Keep getting a DELETE 400 (Bad Request) with my REST API

So, I’ve created a API and I’ve got my POST and GET requests working, but I’m can’t get the DELETE request to work. I keep getting a ‘DELETE http://localhost:3000/api 400 (Bad Request)’ error in the console.

Here is the delete section in my server file:

JavaScript

Here is the button that executes the DELETE:

JavaScript

It says that the bad request comes from fetch(‘/api’, options);, but I have no idea how to fix it! Can anyone help me?

Advertisement

Answer

The error may be due to the fact that delete request should not receive a json body, you should pass the uid as a path variable like:

JavaScript

And change your call to:

JavaScript
Advertisement