19 C Mumbai
Wednesday 22nd January 2025
A Quick Guide to HTTP Methods and Status Codes
By seoerland

A Quick Guide to HTTP Methods and Status Codes

HTTP Request Methods

HTTP (Hypertext Transfer Protocol) is used for communication between the client (typically a browser) and the server. HTTP request methods (also known as HTTP verbs) define the type of operation a client wants to perform on the server. Common HTTP request methods include:

GET

Purpose: Request data from the specified resource (usually for viewing or retrieving information).

Characteristics:

The data requested does not modify the resource’s state on the server (i.e., it is a read-only operation).

GET requests can be cached and are stored in the browser’s history.

Parameters are usually included in the URL.

Example: GET /index.html HTTP/1.1

POST

Purpose: Submit data to the specified resource, typically used for form submissions or creating new resources.

Characteristics:

Data is sent in the body of the request, rather than in the URL.

POST requests modify the server’s state (e.g., creating a new record in the database).

POST requests are not cached and do not appear in the browser history.

Example: POST /submit_form HTTP/1.1

PUT

Purpose: Update or create the specified resource, typically for modifying existing data.

Characteristics:

PUT requests replace the specified resource with the data in the request body.

If the resource does not exist, PUT can create it.

PUT requests are usually idempotent (i.e., multiple identical requests will have the same effect).

Example: PUT /user/123 HTTP/1.1

DELETE

Purpose: Delete the specified resource.

Characteristics:

DELETE requests remove resources from the server.

DELETE requests are typically idempotent, meaning repeated requests do not produce additional effects.

Example: DELETE /user/123 HTTP/1.1

PATCH

Purpose: Partially update the specified resource, rather than replacing the entire resource.

Characteristics:

Suitable for modifying part of a resource rather than the whole resource.

Lighter weight compared to PUT for making partial changes.

Example: PATCH /user/123 HTTP/1.1

HEAD

Purpose: Similar to GET, but does not return the resource content, only the response headers.

Characteristics:

Used to retrieve metadata about a resource (e.g., last modified date, content type) without downloading the actual content.

Suitable for checking resource status before requesting full data.

Example: HEAD /index.html HTTP/1.1

OPTIONS

Purpose: Query the server for which HTTP methods are supported by the resource, often used for CORS (Cross-Origin Resource Sharing) requests.

Characteristics:

Clients can use the OPTIONS method to determine the supported request methods for a resource.

Example: OPTIONS /api/resource HTTP/1.1

CONNECT

Purpose: Establish a tunnel to the target server (typically for HTTPS requests).

Characteristics:

Commonly used by proxy servers to allow the client to establish a secure connection to a remote server.

Example: CONNECT example.com:443 HTTP/1.1

TRACE

Purpose: Trace the path of a request, useful for debugging.

Characteristics:

TRACE responses echo back the content of the request, helping with diagnostics.

Example: TRACE / HTTP/1.1

Nine ways to request
get、post、head
options、put、delete
trace、connect、patch

Common HTTP Status Codes

HTTP status codes are used to indicate the result of the server’s attempt to process a request. The common HTTP status codes are grouped into five categories:

1xx – Informational Status Codes

These status codes indicate that the request has been received and is being processed:

100 Continue: The request has been received, and the client should continue sending the rest of the request.

101 Switching Protocols: The server is switching to a different protocol as requested by the client.

2xx – Success Status Codes

These status codes indicate that the request was successful and the server has processed the request:

200 OK: The request was successful, and the server returned the requested data (usually for GET or POST requests).

201 Created: The request was successful, and the server has created a new resource.

202 Accepted: The request was accepted, but it has not been fully processed (e.g., asynchronous tasks).

204 No Content: The request was successful, but there is no content to return.

Example 2 Success
3xx – Redirection Status Codes

These status codes indicate that the client must take further action to complete the request:

301 Moved Permanently: The requested resource has permanently moved to a new location. The client should use the new URL.

302 Found: The requested resource has temporarily moved to another location. The client should continue using the original URL.

304 Not Modified: The resource has not been modified since the last request. The client can use its cached version.

3xx Redirect
3xx Redirect
Example 3 Redirect
4xx – Client Error Status Codes

These status codes indicate that there was an error in the request made by the client:

400 Bad Request: The request is invalid, likely due to malformed syntax or missing required parameters.

401 Unauthorized: The request requires authentication; the client must provide valid credentials.

403 Forbidden: The server understands the request but refuses to authorize it (insufficient permissions).

404 Not Found: The requested resource could not be found on the server.

405 Method Not Allowed: The HTTP method used is not allowed for the resource (e.g., POST for a resource that only supports GET).

408 Request Timeout: The server timed out while waiting for the client to send the full request.

429 Too Many Requests: The client has sent too many requests in a given time period, and the server cannot handle the request.

4xx Client Error
4xx Client Error.
Example 4 Client Error
5xx – Server Error Status Codes

These status codes indicate that the server failed to fulfill a valid request:

500 Internal Server Error: The server encountered an unexpected condition and could not process the request.

502 Bad Gateway: The server, acting as a gateway or proxy, received an invalid response from the upstream server.

503 Service Unavailable: The server is temporarily unavailable, usually due to being overloaded or undergoing maintenance.

504 Gateway Timeout: The server, acting as a gateway or proxy, did not receive a timely response from the upstream server.

5xx Server error
Need Assistance?

If you have any questions or need support, don’t hesitate to contact our team. We’re here to assist you!

  • No Comments
  • December 25, 2024