DELETE Request to Delete a User
Example: In this example the endpoint deletes the user with the specified id from the server. After deletion, the user will no longer exist in the database.
//delete_request.js
const axios = require('axios');
axios.delete('http://localhost:3000/users/3/')
.then(resp => {
console.log(resp.data)
}).catch(error => {
console.log(error);
});
Run the below command to test the PUT Request:
node delete_request.js
Output:
{
id: '3',
first_name: 'Shreya',
last_name: 'def',
email: 'shreya@gmail.com'
}
How to Create A REST API With JSON Server ?
Setting up a RESTful API using JSON Server, a lightweight and easy-to-use tool for quickly prototyping and mocking APIs. JSON Server allows you to create a fully functional REST API with CRUD operations (Create, Read, Update, Delete) using a simple JSON file as a data source.
Table of Content
- GET Request Returns a List of all Users
- POST Request to create a New User
- PUT Request to Update an Existing User
- DELETE Request to Delete a User