🧠 HTTP Methods & Status Codes β€” Cheatsheet

HTTP Diagram


πŸš€ Most Commonly Used HTTP Methods

GET

πŸ”Ή Has only headers
Retrieve a specific resource or collection of resources.
Should not affect data or resources.
βœ… Can be cached
⚠️ Avoid sending sensitive data
πŸ“ Has length restrictions (can’t send large files)


POST

πŸ”Ή Has headers and body
Creates a new resource.
Each POST request should create a new resource with a unique ID.
🚫 Never cached.


PUT

πŸ”Ή Has headers and body
Updates a specific resource (by ID).
Replaces all current representations of the target resource with the uploaded content.


PATCH

πŸ”Ή Has headers and body
Updates partial resources.


DELETE

πŸ”Ή Has headers and body
Removes a specific resource by ID.
Removes all current representations of the target resource given by a URI.


🧩 Other HTTP Methods

πŸ”Ή Has only headers
Same as GET but does not return a body β€” only headers and status line.
Used for obtaining meta-information about the entity.


OPTIONS

πŸ”Ή Has headers and body
Used to check supported HTTP methods (communication options) for the target resource.


CONNECT

Establishes a tunnel to the server identified by a given URI.


TRACE

Echoes the received request so a client can see what (if any) changes or additions have been made by intermediate servers.

⚠️ Security note: TRACE can enable malicious parties to steal cookies or credentials via XSS.
Disable TRACE requests in server configuration.


🧾 HTTP Status Codes

CodeMeaning
100Continue
200OK
201Created
202Accepted
204No Content
302Found (URL redirection or use 303)
400Bad Request
401Unauthorized
402Payment Required
403Forbidden
404Not Found
408Request Timeout
500Internal Server Error
503Service Unavailable

πŸ“Š HTTP Status Code Categories

CategoryDescription
1xxInformational
2xxSuccess
3xxRedirection
4xxClient Error
5xxServer Error

πŸ«– 418 β€” I’m a teapot (1998 April Fools’ joke)
You can also define custom error codes and descriptions.


πŸ“¨ Fields in HTTP Request Headers

Example of HTTP Message Headers

GET /hello.html HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

Meaning

  • Line 1: Method, URI, and HTTP version (GET /hello.html HTTP/1.1)
  • Line 2: User-Agent β€” Client browser info, where the request originates from
  • Line 3: Host β€” Specifies the Internet host and port number of the resource
  • Line 4: Accept-Encoding β€” Restricts acceptable content-codings in the response
  • Line 5: Connection β€”
    Using "keep-alive" keeps the TCP connection open for subsequent requests,
    improving performance and reducing CPU load via persistent connections