HTTP METHODS

 HTTP METHODS

GET Method:

The HTTP GET method is used to read/ retrieve a representation of a resource. In the happy path ( non-error), GET returns a representation in XML or JSON and an HTTP response code of 200 (OK). In an error case, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST).

POST Method:

The POST verb is most-often utilized to create new resources. In other words, when creating a new resource, POST to the parent and the service takes care of associating the new resource with the parent, assigning an ID (new resource URI), etc.

On successful creation, return HTTP status 201, returning a Location header with a link to the newly-created resource with the 201 HTTP status.In an error case 404 (Not Found), 409 (Conflict) if resource already exists.

PUT Method:

PUT is most-often utilized for update capabilities, PUT-ing to a known resource URI with the request body containing the newly-updated representation of the original resource.

On successful update, return 200 (or 204 if not returning any content in the body) from a PUT. If using PUT for create, return HTTP status 201 on successful creation. In an error case 404 (Not Found), 405 (Method Not Allowed)

DELETE Method:

DELETE is pretty easy to understand. It is used to delete a resource identified by a URI.On successful deletion, return HTTP status 200 (OK) along with a response body or return HTTP status 204 (NO CONTENT) with no response body. Calling DELETE on a resource a second time will often return a 404 (NOT FOUND) since it was already removed and therefore is no longer findable.

PATCH Method:

PATCH is used for modify capabilities. The PATCH request only needs to contain the changes to the resource, not the complete resource.On successful updation return HTTP status code 200 (OK) or 204 (No Content), in case of failure 405 (Method Not Allowed).












SUMMARY TABLE:

HTTP Verb/ Methods

      OPERATIONS

(CRUD)

RESPONSE

(When Request is Successful)

RESPONSE

(When Request is Fail)

GET

Read/retrieve

200 (OK)

404 (Not Found)

POST

create/update a resource

201 (Created)

404 (Not Found), 409 (Conflict) if resource already exists.

PUT

Update/Replace

200 (OK) or 204 (No Content)

404 (Not Found), 

405 (Method Not Allowed)

DELETE

Delete

200 (OK)

204 (NO CONTENT) with no response body

404 (Not Found),

405 (Method Not Allowed)

PATCH

Update/Modify

200 (OK) or 204 (No Content)

405 (Method Not Allowed)





THANKS!!


Comments

Popular posts from this blog

Python namespaces & LEGB rule in Python