Recap in HTTP design




Some of the common stuff when it comes to responding to REST based API are as follows :-

1. GET - 200 for OK, 404 when not found

2. POST - 201 for created and 204 No update. Returns 404 if it is a bad request. Returns 409 when conflict.

For long running or async processes, an API could just return 202 (ACCEPTED) with a link to poll status info. Agent can poll the status and once upon completed returns 303.
Results can be show here :-

HTTP/1.1 202 Accepted Location: /api/status/12345


HTTP/1.1 303 See Other Location: /api/orders/12345


3. PUT - 201 for created and 204 No update. Returns 409 when conflict.

4. PATCH - this is mainly used for update resource. It will return 415 for unsupported media, 400 bad request and 409 for conflict.

5. HEAD - for handling large content


If you have a long running task or wanted to poll status of a resources, then you can do something like this :-

POST to a resource and returns 202 (Accepted) with a location of resource URL. 

Issue GET on the new location resource 

Return 303 if creates a new resource and returns locations of the newly created resource url. 




Comments

bhanu sreee said…
This information is really awesome thanks for sharing the most valuable information.
Mulesoft Training in Hyderabad
Mulesoft Training in Bangalore

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm