HTTP Protocol Cheat Sheet
HTTP(Hyper Text Transfer Protocol) is used in Client & Web Server interactions in distributed, Multi-Tier applications, as shown below.
HTTP is one of the most widely used Network Protocol.
As known HTTP is a request/response based protocol, where a Web Client(Web Browser, POST Man, Mobile App, etc…) sends an HTTP request and Web Server(such as Apache Tomcat, Websphere, Web Logic, etc…) responds with response data along with HTTP Status code
HTTP Request contains:
- URL(with Path Variables, Query Parameters)
- HTTP Method
- HTTP Headers
- Request Body(in XML or JSON Format or even in binary)
- Cookie(Optional)
Path Variables in Http Request:
Query Parameters in Http Request:
http://someurl.com?age=25&gender=male
HTTP Response contains:
- HTTP status code
- HTTP Headers
- Response Body(in XML or JSON Format)
HTTP Methods: Below are commonly used HTTP Methods, (Consider Flight Ticket as a resource here)
GET — to retrieve a resource(retrieve a specific Flight Ticket details, which was already booked earlier)
POST — to create a resource(to book a new Flight Ticket)
PUT — to update a resource(to update Journey Date of a Flight Ticket)
DELETE — to delete a resource(to Cancel a Flight Ticket)
PURGE — to delete resource from Caching Servers
TRACE — Web Server sends a received Request back to Client, TRACE is used for debugging Http Request
HTTP Status codes: HTTP Status code is part of Http response, and indicates the result of processing an HTTP request. Whether an HTTP request has been processed successfully or if there was an issue in handling Http request.
Below is list of Http status code series and purpose of it
100 to 199 — Informational response
200 to 299 — Successful response, such as 200-OK, 201-Created(i..e Resource created successfully on Server)
300 to 399 — redirect the Http request to some other URL
400 to 499 — Client side errors, such as 400-Bad Request, 401&403-not authorized to access, 404-resource doesn’t exist
500 to 599 — Server side errors, such as there was internal error in Web Server, either due to application or configuration of Webserver
Some built-in HTTP Headers:
HTTP Headers hold meta data related to Http request or response. Below are commonly used Http Headers
- Content Type of request/response Data(For eg. Content-Type — indicates Media Type of Request/Response body, Accept , Accept-Language),
- Caching related(For eg. Cache-Control, Expires, etc…)
- Authentication related(For eg. Authorization)
- Other General Http headers(For eg. Last-Modified, Cookie, Set-Cookie, Location, etc…)
Authentication Support:
HTTP has inbuilt support for below Authentication protocols
- Basic Authentication
- Digest Authentication
Some more details of HTTP:
Web Server by default listens on port 80(it’s not 8080) for HTTP. And for HTTPS 443 is default port number.
HTTP is independent of Programming Language/Framework or Operating Systems(i..e Web Client, Web Server applications developed in different Programming Languages can operate together seamlessly)
HTTP is state less protocol
REST API services can be developed using HTTP(or HTTPS) protocol only.
REST is used to develop SOA(Service Oriented Architectures), and is light weight compared to SOAP
HTTP uses TCP/IP protocol internally