Alyssa
Alyssa

Reputation: 153

How can I delete a user from my restful API

In my application, I have a set of users in a data table. From this data table, I would like to be able to delete users from the table on both the front-end and the backend. I am using http requests to do so, the 'DELETE' request, but for some reason I keep getting 403 errors.

I am using the axios NPM package to use the delete request, but I'm starting to think it may not be the best solution. I'm open to any and all solutions to be able to do this function.

What I have so far is as follows:

 function onAfterDeleteRow(rowKeys) {
   alert('The rowkey you drop: ' + rowKeys);
   axios.delete('https://api.exampleapi.com/api/v1/users/{id}', {
       params: {
         id: '1'
     }
   });
  }

I'm expecting that once I press the delete button that I have in the table, I will be able to delete the user on the front-end (which works, you can see the row is visibly gone) but then I also want to permanently remove the user from my api as well. Just wondering what is wrong with my code.

Upvotes: 1

Views: 829

Answers (1)

Matthew Kulina
Matthew Kulina

Reputation: 11

From my understand, the param you're passing is the id of the user. So you're always passing 1? You need to associate which user id you want to delete in your function.

axios.delete('https://api.exampleapi.com/api/v1/users/ + rowKeys} if I understand rowKeys as being the userID.

This is all without knowing how your controller is working for this.

Upvotes: 1

Related Questions