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"
                    	}
                      
  • PUT: This method is used to update or replace an entire resource. If the resource identified by the URI exists, it is updated; otherwise, a new resource might be created at that URI. PUT is idempotent, meaning multiple identical PUT requests will have the same effect as a single request.
    • Code
    • PUT /users/123
    • 
                      Content-Type: application/json
                      {
                    	"id": 123,
                    	"name": "Jane Doe",
                    	"email": "jane.doe@example.com"
                    	}
                      
  • PATCH: This method is used to partially update an existing resource. Unlike PUT, which replaces the entire resource, PATCH applies a set of changes to specific fields of the resource without affecting others.
    • Code
    • PATCH /users/123
    • 
                     	Content-Type: application/json
                      {
                      "email": "new.email@example.com"
                      }
                      
                    
  • DELETE: This method is used to remove a specified resource from the server.
    • Code
    • DELETE /users/123