Core Web API Interview Questions : Part 1
In this part, we have listed Core Web API Questions and answers.
Question 1: What is the difference between GET, POST, PUT, PATCH and DELETE in REST API?
The primary difference between GET, POST, PUT, PATCH, and DELETE in a REST API lies in their intended purpose and how they interact with resources on a server:
- GET: This method is used to retrieve data from a specified resource. It is a read-only operation and should not have any side effects on the server. GET requests can be cached and bookmarked.
- Code
- GET /users/123
- POST: This method is used to create a new resource on the server. Data is sent in the request body, and the server processes this data to generate a new resource.
- Code
- POST /users
Content-Type: application/json { "name": "John Doe", "email": "john.doe@example.com" }
- Code
- PUT /users/123
Content-Type: application/json
{
"id": 123,
"name": "Jane Doe",
"email": "jane.doe@example.com"
}
- Code
- PATCH /users/123
Content-Type: application/json
{
"email": "new.email@example.com"
}
- Code
- DELETE /users/123