HTTP stands for "HyperText Transfer Protocol," and it's the computer communication protocol used for most communication on the world wide web. The protocol is the set of rules that actually conducts the client/server interaction between your web browser and the destination web page.
The primary or most commonly-used HTTP methods are POST, GET, PUT, PATCH, and DELETE. These methods correspond to create, read, update, and delete (or CRUD) operations, respectively. There are a number of other methods, too, but they are utilized less frequently.
GET
The HTTP GET method is used to read (or retrieve) a representation of a resource. In case of success (or non-error), GET returns a representation in JSON and an HTTP response status code of 200 (OK). In an error case, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST).
Note
According to the design of the HTTP specification, GET requests are used only to read data and not change it. So, they are considered safe. That is they can be called without risk of data modification or corruption—calling it once has the same effect as calling it 10 times.
POST
The POST method is most often utilized to create new resources. In particular, it is used to create subordinate resources. That is subordinate to some other (e.g. parent) resource. 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, HTTP response code 201 is returned.
Caution
POST is not a safe operation. Making two identical POST requests will most likely result in two resources containing the same information but with different identifiers.
Note
It is possible to create both primary and related API resources via a single API request
For some resources, you can create a resource (if it did not already exist) or update it (if it does) via a single API request.
PATCH
PATCH is used to modify resources. The PATCH request only needs to contain the changes to the resource, not the complete resource.
In other words, the body should contain a set of instructions describing how a resource currently residing on the server should be modified to produce a new version.
Caution
PATCH is not a safe operation. Collisions from multiple PATCH requests may be dangerous because some patch formats need to operate from a known base point; otherwise, they will corrupt the resource. Clients using this kind of patch application should use a conditional request (e.g., GET a resource, ensure it was not modified and apply PATCH) such that the request will fail if the resource has been updated since the client last accessed the resource.
DELETE
DELETE is quite easy to understand. It is used to delete a resource identified by filters or ID.
On successful deletion, the HTTP response status code 204 (No Content) returns with no response body.
Important
If you DELETE a resource, it is removed. Repeatedly calling DELETE on that resource will often return a 404 (NOT FOUND) status code since it was already removed and, therefore, is no longer findable.
HTTP STATUS CODE
1xx - Informational
- 100 Continue: The request is being processed, and the client should continue sending the request body.
- 101 Switching Protocols: The client has requested a change in protocol, and the server is acknowledging the request.
2xx - Success
- 200 OK: The request was successful, and the response body contains the requested data.
- 201 Created: The request was successful, and a new resource was created.
- 202 Accepted: The request was accepted, but the processing has not been completed.
- 203 Non-Authoritative Information: The server is returning information from a cache or another source, but the information may not be up-to-date.
- 204 No Content: The request was successful, but there is no response body.
- 205 Reset Content: The request was successful, and the client should reset the document view.
- 206 Partial Content: The server is delivering only part of the requested resource.
3xx - Redirection
- 300 Multiple Choices: The requested resource has multiple representations, and the client can choose one.
- 301 Moved Permanently: The requested resource has been permanently moved to a new location.
- 302 Found: The requested resource has been temporarily moved to a new location.
- 303 See Other: The requested resource can be found at a different location.
- 304 Not Modified: The requested resource has not been modified since the last request.
- 305 Use Proxy: The requested resource must be accessed through a proxy.
- 307 Temporary Redirect: The requested resource has been temporarily moved to a new location.
- 308 Permanent Redirect: The requested resource has been permanently moved to a new location.
4xx - Client Error
- 400 Bad Request: The request was invalid or cannot be processed.
- 401 Unauthorized: The client is not authorized to access the requested resource.
- 402 Payment Required: The requested resource requires payment.
- 403 Forbidden: The client is not allowed to access the requested resource.
- 404 Not Found: The requested resource was not found.
- 405 Method Not Allowed: The request method is not allowed for the requested resource.
- 406 Not Acceptable: The requested resource is not available in the requested format.
- 407 Proxy Authentication Required: The client must authenticate with a proxy.
- 408 Request Timeout: The request took too long to process.
- 409 Conflict: The request conflicts with another request or resource.
- 410 Gone: The requested resource is no longer available.
- 411 Length Required: The request must specify a content length.
- 412 Precondition Failed: A precondition specified in the request failed.
- 413 Payload Too Large: The request payload is too large.
- 414 URI Too Long: The request URI is too long.
- 415 Unsupported Media Type: The request media type is not supported.
- 416 Range Not Satisfiable: The requested range is not available.
- 417 Expectation Failed: An expectation specified in the request failed.
- 418 I'm a teapot: The server is a teapot and cannot brew coffee.
- 421 Misdirected Request: The request was sent to the wrong server.
- 422 Unprocessable Entity: The request was well-formed but cannot be processed.
- 423 Locked: The requested resource is locked.
- 424 Failed Dependency: A dependency specified in the request failed.
- 425 Too Early: The request was sent too early.
- 426 Upgrade Required: The client must upgrade to a different protocol.
- 428 Precondition Required: A precondition is required for the request.
- 429 Too Many Requests: The client has sent too many requests.
- 431 Request Header Fields Too Large: The request header fields are too large.
- 451 Unavailable For Legal Reasons: The requested resource is unavailable for legal reasons.
5xx - Server Error
- 500 Internal Server Error: The server encountered an unexpected error.
- 501 Not Implemented: The requested method is not implemented by the server.
- 502 Bad Gateway: The server received an invalid response from another server.
- 503 Service Unavailable: The server is currently unavailable.
- 504 Gateway Timeout: The server did not receive a response from another server in time.
- 505 HTTP Version Not Supported: The requested HTTP version is not supported by the server.
- 506 Variant Also Negotiates: The requested resource has multiple variants, and the client must negotiate.
- 507 Insufficient Storage: The server does not have enough storage to fulfill the request.
- 508 Loop Detected: A loop was detected in the request.
- 510 Not Extended: The requested extension is not supported by the server.
- 511 Network Authentication Required: The client must authenticate with the network.