DEV Community

loading...
Cover image for HTTP Methods, Status Codes and their meaning

HTTP Methods, Status Codes and their meaning

sai_karthik profile image Sai Karthik ・3 min read

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 (100–199)
  • Successful responses (200–299)
    200 OK: The request was completed successfully.

  • Redirects (300–399)
    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 (400–499)
    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 (500–599)
    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

Discussion (0)

pic
Editor guide