Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 20, 2020 04:43 pm GMT

HTTP Methods, Status Codes and their meaning

Have you ever wondered what's the difference between GET and POST requests, or what does 404 Not Found means? You're not alone. Having a basic understanding of the different HTTP Methods and HTTP Status Codes is important when you're exploring and testing APIs.

HTTP Methods:

Below are some common HTTP methods. Let's discuss what each of them means.

GET:

GET method is used to retrieve data from a server at the specified resource.
GET is often the default method in HTTP clients

POST:

POST requests are used to send data to the API server to create or update a resource. The data sent to the server is stored in the request body of the HTTP request.
The simplest example is a contact form on a website. When you fill out the inputs in a form and hit Send, that data is put in the response body of the request and sent to the server.

PUT:

Similar to POST, PUT requests are used to send data to the API to update or create a resource. The difference is that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the same result. In contrast, calling a POST request repeatedly make have side effects of creating the same resource multiple times.

PATCH:

PATCH is used for modifying capabilities. The PATCH request only needs to contain the changes to the resource, not the complete resource.
This resembles PUT, but the body contains a set of instructions describing how a resource currently residing on the server should be modified to produce a new version. This means that the PATCH body should not just be a modified part of the resource, but in some kind of patch languages like JSON Patch or XML Patch.

DELETE:

DELETE is pretty easy to understand. It is used to delete a resource identified by a URI.

HTTP Response Status Codes:

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped into five classes. Let's touch upon some most common HTTP response status codes from all these classes in this blog.

  • Informational responses (100199)
  • Successful responses (200299)
    200 OK: The request was completed successfully.

  • Redirects (300399)
    301 Moved Permanently: The resource is permanently located in a different URI. A new URI should be given in the response.
    302 Found: The resource temporarily moved to a new location.

  • Client errors (400499)
    400 Bad Request: The request could not be understood by the server.
    401 Unauthorized: The request has not been applied because it lacks valid authentication credentials for the target resource.
    403 Forbidden: User not authorized to perform the requested operation.
    404 Not Found: The requested resource could not be found at the given URI.
    405 Method Not Allowed: The request method is not allowed on the specified resource.

  • Server errors (500599)
    500 Internal Server Error: The server encountered an unexpected condition, preventing it to fulfill the request.
    503 Service Unavailable: The server is temporarily unavailable, usually due to overloading or maintenance.
    504 Gateway Timeout: The server is a gateway or proxy server, and it is not receiving a response from the backend servers within the allowed time period.

Further References:

Here are some resources where you can refer to more of these HTTP Methods and HTTP Response Status Codes.
MDN - HTTP Methods
MDN - HTTP Response Status Codes


Original Link: https://dev.to/sai_karthik/http-methods-status-codes-and-their-meaning-1nfc

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To