HTTP Verbs

HTTP request methods

What is HTTP?

The main purpose of Hypertext Transfer Protocol (HTTP) is to enable communication between clients and servers. It uses the request-response method.

For that HTTP defines set of request methods to identify which action should be performed for the resources. Also referred as HTTP Verbs.

HTTP Methods :

  • GET
  • POST
  • PUT
  • DELETE
  • PATCH
  • OPTIONS
  • HEAD

The two most common HTTP methods are: GET and POST.

GET

GET is used to fetch data from a specified resource. Only use to only retrieve data.

Retrieve all :

https://sliit.lk/api/v1/faculties

Retrieve one :

https://sliit.lk/api/v1/faculties/ {faculty id}

Properties of GET requests:

  • GET requests can be cached
  • GET requests remain in the browser history
  • GET requests should never be used when dealing with sensitive data
  • GET requests have length restrictions
  • GET requests are Safe (only used to request data not modify)

POST

POST is used to create an entry to specific resource. Data sent to the server via POST is stored in request body.

https://sliit.lk/api/v1/faculties

Properties of POST requests:

  • POST requests are never cached
  • POST requests do not remain in the browser history
  • POST requests have no restrictions on data length
  • POST requests are non-safe because we add new entry.

PUT

Put method replace current entry with new data.

https://sliit.lk/api/v1/faculties/{faculty id}

Difference between POST and PUT, POST method is non-safe while PUT method is idempotent. That means, by calling a PUT request what we really do is manipulating an existing entry unlike POST where it will create a new entry. 

DELETE

The DELETE method deletes the specified resource.

https://sliit.lk/api/v1/faculties/{faculty id}

PATCH

The PATCH method is used to apply partial modifications to a resource.

OPTIONS

OPTIONS method will return all the allowed communication options for the target resource.

HEAD

The HEAD method asks for a response identical to that of a GET request, but without the response body.

Comments

Popular posts from this blog

What is JavaScript?