Axios delete giving 404 after deleting from database

Asked
Active3 hr before
Viewed126 times

9 Answers

givingdeleteaxios
90%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,I am sending a delete request using axios from my React frontend to node js express backend with mongo DB. Although the data does get deleted from my database but I still get an error 404 Not Found.,Please note that the entry gets deleted from my database but i get this error in my browser console :

Try modifying the res to send a 200 OK status if the object gets deleted. You could also send a message for your frontend to display in this manner

if (!err) {
   res.status(200).json({
      message: 'The item got successfully deleted',
      error: false
   });
} else {
   res.status(500).json({
      message: 'Oops and error occurred',
      error: true
   });
88%

Im trying to delete a record from a MongoDB database on localhost:4000 using Axios and React.,I wonder if you can help me please?,Using the following code I can retreive a record using Axios GET request via a button.

React Button and Axios Methods

       <button onClick={
     function(e){
         e.preventDefault();
         axios.get(`http://localhost:4000/todos/5e986e3a2f2b21bfa3a76f6f`)
         .then( (res) => console.log(res.data));

         axios.delete(`http://localhost:4000/todos/5e986e3a2f2b21bfa3a76f6f`)
         .catch(function(error){
         console.log(error.response);
        })
      }
}>Delete</button>
load more v
72%

When using the alias axios.delete, the payload doesn't get sent with the API call if you don't specify data.,According to this, you shouldn't have to define data. I've been able to use other methods with payload without specifying data.,In my case, I do give a payload as well. But either way, if it works using data, it should work using the shorthand.

axios.delete(URL, {
   data: {
      foo: 'bar'
   }
})
load more v
65%

Pretag
 Pretag team - issue, fix, solve, resolve
75%

Pretag
 Pretag team - issue, fix, solve, resolve
40%

DELETE - This is used to delete data from the server.,404 - This is used to indicate a "Resource NOT Found" message when HTTP doesn't find the specified URL at the server.,GET - This is used to get data from the server.

1
import {
   BrowserModule
} from "@angular/platform-browser";
2
import {
   HttpClientModule
} from "@angular/common/http";
3
4
import {
   NgModule
} from "@angular/core";
5
import {
   AppComponent
} from "./app.component";
6
7 @NgModule({
   8 declarations: [AppComponent],
   9 imports: [BrowserModule, HttpClientModule],
   10 providers: [],
   11 bootstrap: [AppComponent]
   12
})
13
export class AppModule {}
load more v
22%

If you want to learn how to send http delete request with react js then i will help you step by step instruction for sending http request using axios react. In this react delete using axios tutorial i will give you very simple example to send http delete request using axios and react.if(typeof __ez_fad_position != 'undefined'){__ez_fad_position('div-gpt-ad-codecheef_org-banner-1-0')};,Axios is a npm package and provide to make http request from our application. In this quick example we will use "jsonplaceholder" api to delete data using axios package.,Hope this react js axois delete request example can help you.

Example Code of React Js Axois Delete Request:

60%

You will need a good knowledge of Laravel, including how to set up a database to use with it. You should have the Laravel CLI installed. Some familiarity with Vue.js will be helpful.,Laravel CLI installed on your machine,Getting started with Laravel

Pretag
 Pretag team - issue, fix, solve, resolve
48%

Each Tutorial has id, title, description, published status.,We can create, retrieve, update, delete Tutorials.,There is a Search bar for finding Tutorials by title.

Pretag
 Pretag team - issue, fix, solve, resolve

Other "giving-delete" queries related to "Axios delete giving 404 after deleting from database"