While designing the
restful API, we need to make sure that API should always return the right and
consistence HTTP status Code and without consistent HTTP status codes, customers
will not know the difference between success or failure without parsing the
response body.
References:
Thanks for Visiting!
HTTP standard provides
almost 70 status codes to describe the response status and you can
use below HTTP status code for restful API.
200 –
OK
204 –
OK – No Content
400 –
Bad Request
401 –
Unauthorized
404 –
Resource Not Found
500 –
Internal Server Error
503 – Service is not available
The above sequence diagram
explain how the HTTP request is being processed and returns the HTTP
status code.
There are the possible
scenarios for processing of the HTTP GET request.
1. Scenario : If request
resource is found, Returns HTTP – 200 OK with Resource data
2. Scenario : If request resource is
not available, return HTTP – 404 Resource
Not Found – with message “Resource is not available”
3. Scenario: Any
Validation Error/invalid input – returns HTTP
– 400 Bad Request with validation or error message.
HTTP – POST (Resource
Creation)
The above sequence diagram
explain how the HTTP request is being processed and returns the right HTTP
status code.
There are the possible
scenarios for processing of the HTTP POST request.
1. Scenario: If requested resource is successfully created, Returns HTTP – 201 OK with Newly
created Resource data
2. Scenario:
If request resource is already found or duplicate
resource, returns – returns HTTP – 400 Bad
Request with validation message
OR
· Any validation or invalid input error -
returns HTTP – 400 Bad Request with
validation message
HTTP – PUT (Resource
Update)
HTTP PUT Sequence Diagram |
The above sequence diagram
explain how the HTTP request is being processed and returns the right HTTP
status code.
There are the possible
scenarios for processing of the HTTP PUT request.
1.
Scenario: Any validation or
invalid input error - returns HTTP – 400 Bad Request with validation
message
2.
Scenario: If request resource is not available, return HTTP – 404 Resource Not Found – with message “Resource is not available”
In this scenario, if resource is not
available, many architect prefer to create new resource and returns HTTP – 201 OK with newly created
resource data
3.
Scenario: If request resource is
available and successfully updated, Returns HTTP – 200
OK with updated Resource data
HTTP – PATCH (Partially Resource Update)
The above sequence diagram
explain how the HTTP request is being processed and returns the right HTTP
status code.
There are the possible
scenarios for processing of the HTTP PATCH request.
1.
Scenario : If request resource is available and successfully updated ,
Returns HTTP – 200 OK with updated
Resource data
2.
Scenario : Any validation or
invalid input error - returns HTTP – 400 Bad
Request with validation message
3.
Scenario : If request resource is not available, return HTTP – 404 Resource Not Found – with message “Resource is not available”
HTTP – DELETE (Delete
Resource)
HTTP DELETE Sequence Diagram |
The above sequence diagram
explain how the HTTP request is being processed and returns the right HTTP
status code.
There are the possible
scenarios for processing of the HTTP DELETE request.
1.
Scenario : If request resource is available and successfully deleted,
Returns HTTP – 200 OK
2.
Scenario
: Any validation or invalid input
error - returns HTTP – 400 Bad Request with
validation message
3.
Scenario : If request resource is not available, return HTTP – 404 Resource Not Found – with message “Resource is not available”
Note: In some scenario, requested URI is not matching with any API URI.,
then by default Web API/IIS returns HTTP – 404 - with message “HTTP resource was found that matches the
request URI”
Thanks for Visiting!
4 comments:
Your post contains a lot of useful information for me. Thank you very much for that.
Mulesoft Online Training
Mulesoft Training in Hyderabad
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this. Thank you for sharing any good knowledge and thanks for fantastic efforts.
oracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
hadoop training in chennai
hadoop training in bangalore
Returning a 404 for a valid endpoint that just returns no data is wrong. Use 200/204 and an empty response or json as an empty array.
Post a Comment