A REST resource enables access to data, but doesn’t in itself do anything with that data. To use a REST resource, we have to pass along instructions about what action we want to perform. This is done using HTTP methods, also called verbs. Anytime you use a web browser, you or rather the browser use HTTP methods to tell the server at the other end of the URL what type of request is being sent.
GET
- Get resource.
- By far the most common of these methods is Get which literally means get what’s at the end of this address and send it to me.
- Anytime you visit a web page or follow a link or click reload or forward or back or any other standard interaction in a browser, you are sending a get request over HTTP.
POST
- Create new resources.
- Post is the most common of these methods and it’s also the one used in regular non-REST scenarios like when you submit a form on a web page.
PUT
- Used to update data at an existing resource by replacing all of its contents with the contents of the new request.
- A put request contains the ID of the resource and the new content to be added to that resource.
- If the resource already exists, the existing content is replaced with the contents of the Put request.
- If no resource exists, the REST server may allow a new resource to be created with the user defined ID.
PATCH
- Patch is used to modify an existing resource.
- Where Put updates the resource by replacing content, Patch can carry along instructions on how to modify the existing resource without necessarily replacing everything.
DELETE
- It deletes the specified resource.
- Delete can only be used with singleton resources. If you try to delete a collection resource, you’ll get a 405 Method Not Allowed statusbecause you should not be able to delete everything at once
OPTIONS
- Returns a description of the communication options for the target resource.
HEAD
- Returns just the head section of that response
Comments