HTTP methods

  • GET - Provides a read only access to a resource.
  • DELETE - Used to remove a resource.
  • PATCH - Update an existing resource.
  • POST to a URL creates a child resource at a server defined URL.
  • PUT to a URL creates/replaces the resource in its entirety at the client defined URL.
  • PATCH to a URL updates part of the resource at that client defined URL.
  • OPTIONS - Used to get the supported operations/verbs on a resource.

idempotent

idempotent http methods are those methods whose impact in the server will be same wether you issue the request only once or multiple times. The following methods are idempotent

  • GET
  • DELETE
  • HEAD
  • PUT
  • OPTIONS

POST method is not idempotent since each request will create a new resources in the server.

HATEOAS

  • Hypermedia as the engine of application state

In HATEOAS, REST API response contains available URIs associated with object. For instance, if you GET an object using HATEOAS REST API, your response may contain links based on your access permision on the object.

GET /books/12345
{
    "book": {
        "book_number": 12345,
        "book_name": "The Mythical Man-Month",
        "links": {
            "buy": "/books/12345/buys",  // For all
            "rent": "/books/12345/rents",  // Library Members
            "delete": "/books/12345/deletes"  // Admin only
        }
    }
}

 

 

Interview Questions


 

1. What is the difference between POST and PUT in HTTP?

In POST, URI is the identifier for the object you want create or update whereas in POST, URI is the identifier for the object (or script file) which is responsible for creating the object you want to create.

  • PUT is idempotent. POST is not.

2. Why is the patch method not idempotent?

The patch method is generally considered as replacing some field values in the resource, which raises this question. Actually, you can use patch method modifying the field values like increamenting field values. Here is a sample patch body message: {"operation": "increment", "salary": "1000"}

3. What is the latest HTTP version?

  • HTTP/3 - introduced in 2022 (around 28% websites use)
  • HTTP/2 - 2015 (35%)
  • HTTP/1.1 - 1997

4. What is the major changes in HTTP/2 from HTTP/1.1?

  • multiplexing: which allows your Browser to fire off multiple requests at once on the same connection and receive the requests back in any order.
  • Header compression