ITPE001 - APIs
Web Request and Response
Publish Date:
What is HTTP?
HTTP or Hypertext Transfer Protocol is an application layer protocol that allows web-based applications to communicate and exchange data between each other.
Understanding the HTTP Request and Response Cycle
- When a user search or access a website it starts a chain of events that allow various devices or software to communicate with each other. This is done by done by a user on a client device or software (a web browser for example) by creating a string or a URL.
- The URL is then read by the software on the client’s device and then the browser will create a request for the URL that the user typed in the browser (https://mndrewdevlog.web.app/) The client will send an HTTP request to the server with the following information: HTTP Method, Requested Resource, Resource Headers.
- The Server receives the HTTP request and processes it.
- The server will check if the request is valid and will generate a response.
- The Server sends an HTTP response to the client together with the following information:
- HTTP Status Code
- Response Headers
- Response Body
- The client receives the HTTP response and processes it.
- If the request is successful, it will show the response body or the requested resource.
- However, if the response it is unsuccessful an error message will be displayed.
- Example - Error
404
: Page or Resource Not Found
- Example - Error
Definition of Terms
- Client
- a computer device or software that tries to access a resource from a server.
- Server
- a computer or software that provides resources to other computers called clients.
- Path
- A path is a part of the URL (Uniform Resource Locator)
- This specifies the location of a specific resource on the server.
Example
- Given URL:
https://mndrewdevlog.web.app/blog/assessment/web-request-and-response/
- Domain Name:
mndrewdevlog.web.app
- Path to a resource:
/blog/assessment/web-request-and-response/
- Verb
- In HTTP a verb pertains to an HTTP Method or HTTP Verb.
- A verb specifies what action is going to be performed on the resource
- List of HTTP Verbs
GET
PUT
POST
PUT
CONNECT
PATCH
What are the common HTTP verbs and what do they do?
Here are 5 common HTTP verbs with their respective operations or Function
Verb | Operations/Function |
---|---|
GET | This method requests a specific resource from the web server. |
POST | This method submits data or information to a specific resource. |
DELETE | This method deletes a specific resource |
PATCH | This method updates a resource |
CONNECT | This method allows a connection tunnel to the server to a specific resource. |
Response Status Code Categories
As part of the HTTP Request and Response cycle status codes help indicate whether a request has been completed.
The status codes are categorized into 5 cases with each specific use case.
HTTP Status Code Range | Purpose or Category | Example |
---|---|---|
100 - 199 | Informational Responses | 100 - Continue |
200 - 299 | Successful Responses | 200 - OK or Successful |
300 - 399 | Redirect Message | 302 - Redirected |
400 - 499 | Client Error Message | 404 - Not Found |
500 - 599 | Server Error Message | 502 - Bad Gateway |
References
- Cloudflare, What is HTTP? - https://www.cloudflare.com/learning/ddos/glossary/hypertext-transfer-protocol-http/
- Jen Strong, The Request/Response Cycle of the Web - https://medium.com/@jen_strong/the-request-response-cycle-of-the-web-1b7e206e9047
- HTTPWG.ORG, HTTP Semantics - https://httpwg.org/specs/rfc9110.html#overview.of.status.codes
- MDN Web Docs:
- HTTP Messages - https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages
- HTTP response status codes - https://developer.mozilla.org/en-US/docs/Web/HTTP/Status