HTTP Basics

What is HTTP?
- •Hypertext Transfer Protocol
- •Foundation of data communication on the web
- •Stateless request-response protocol
- •Client-server communication model
HTTP Request Structure
- •Request line (HTTP method, URL, HTTP version)
- •Headers (metadata about the request)
- •Empty line
- •Message body (optional)
HTTP Methods
- •GET: Retrieve data
- •POST: Create new resources
- •PUT: Update existing resources (complete replacement)
- •PATCH: Partial update of resources
- •DELETE: Remove resources
- •OPTIONS: Get supported methods for a resource
- •HEAD: GET without response body
HTTP Status Codes
- •1xx: Informational responses
- •2xx: Successful responses
- •200 OK, 201 Created, 204 No Content
- •3xx: Redirection messages
- •301 Moved Permanently, 304 Not Modified
- •4xx: Client error responses
- •400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
- •5xx: Server error responses
- •500 Internal Server Error, 503 Service Unavailable
HTTP Headers
- •Content-Type: Media type of the resource
- •Authorization: Authentication credentials
- •User-Agent: Client application
- •Accept: Media types accepted by the client
- •Cache-Control: Caching directives
HTTP in Express.js
Recommended Image
A diagram showing the HTTP request-response cycle between client and server,
with labeled components of requests and responses including methods, status
codes, and headers.
Further Reading
- •[MDN Web Docs: HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP)
- •[HTTP Made Really Easy](https://www.jmarshall.com/easy/http/)
- •[Understanding HTTP Basics](https://medium.com/swlh/understanding-http-basics-for-beginner-c2670dc906a3)
- •[RESTful API HTTP Methods](https://restfulapi.net/http-methods/)