Request Types and Status Code In REST APIs

Posted By : Rohit Lakra | 31-Oct-2018

What is REST APIs? What are its advantages?

REST stands for Representational State Transfer.
It just transfers the state of any REpresentation from WebServer to WebClient.
REST works on the HTTP protocols and is a web standards-based architecture.
It revolves around resource and a resource is accessed by a common interface by using HTTP standard methods.
Its output is JSON format as JSON is lightweight and fast processed as compared to XML.


Advantages:-


1. Using REST APIs we can build a loosely coupled application(i.e );
2. It is independent of platform and languages.
3. Flexible and scalable;
4. Easy to use.
5. Not constrained in one format(can return JSON,XMLetc.);

 

REST APIs works on HTTP protocol which is widely used.

 

 HTTP methods:-

1. GET − It is used to read data from a resource.

2. POST − It is used to create a new resource.

3. DELETE − It is used to remove a resource.

4. PUT − It is used to update a resource.

5. PATCH − It is used to make a partial update on a resource.    

 

HTTP Status Codes in REST APIs

 

REST APIs use the Status-Line to inform clients of their request's result.

1. 200(OK):- It indicates that the client's request has been successfully completed. It is associated with the GET method request.

2. 201(CREATED):- It indicates that a resource has been created.

3. 202(Accepted):- This status is used for the requests which have been accepted for the processing but has not completed.

4.  204(NO CONTENT):- When a REST API declines to send back any representation in the response message's body. It is associated with PUT, POST or DELETE request.

eg:-When it is indicated with the GET request that means requested resource exists but it has no representation state to include in the body.

5. 301(Moved Permanently):- It indicates that the requested page has been moved to new URL.

6. 302(FOUND):- It indicates that the requested page has temporarily moved to new URL.     

7. 400(BAD REQUEST):- When the server does not understand the request or no other appropriate error code is available.

8. 401(UNAUTHORIZED):- It indicates that a valid username or password is required.

9. 404(NOT FOUND):- It indicates that the server can't find the requested page.

10. 415(UNSUPPORTED MEDIA TYPE):- It indicates that file type not supported.

11. 500(INTERNAL SERVER ERROR):- It indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

About Author

Author Image
Rohit Lakra

.

Request for Proposal

Name is required

Comment is required

Sending message..