HTTP Methods and Headers
HTTP Methods
The following are the common HTTP methods and their functions. These HTTP methods correspond to the
CRUD (Create, Read, Update, Delete) operations, and they play a crucial role in building RESTful APIs
and web applications.
1. GET:
• The GET method requests a representation of a specific resource.
• It is used to retrieve data from a web server.
• The server responds to a GET request with the requested data (such as a web page or an API
response).
• GET requests should only retrieve data and should not cause any side effects on the server.
• Example: fetching a list of articles from a blog or retrieving user profiles.
2. POST:
• The POST method submits an entity (data) to a specified resource.
• It is commonly used for creating new records or submitting form data.
• A POST request often causes a change in state on the server (e.g., adding a new item to a
database).
• Example: submitting a new blog post, creating a user account, or sending data to an API endpoint.
3. PUT:
• The PUT method replaces all current representations of the target resource with the request
payload.
• It is used for updating existing resources.
• A PUT request provides the entire updated representation of the resource.
• Example: updating a user’s profile information or modifying an existing blog post.
4. DELETE:
• The DELETE method deletes the specified resource.
• It is used to remove a resource from the server.
• The server responds to a DELETE request by removing the resource permanently.
• Example: deleting a user account or removing a blog post.
HTTP Headers
HTTP headers provide additional metadata accompanying HTTP requests and responses, conveying essential
information about the data being transmitted. Here are the key points about HTTP headers:
1. General Information:
• HTTP headers are case-insensitive.
• Header fields are separated by colons (:).
• Headers consist of key-value pairs in clear-text string format.
• The end of the header section is denoted by an empty field.
• Headers can be categorized context-wise:
– General Header: Applies to both request and response headers without affecting the message
body.
1
– Request Header: Contains information about the client’s fetched request.
– Response Header: Contains details about the requested resource’s location.
– Entity Header: Provides information about the resource’s body (e.g., MIME type, content
length).
2. Common Types of Headers:
• Authorization: Used to request restricted documents.
• Cache-Control: Specifies caching directives for mechanisms.
• Expires: Defines the date/time after which the resource will expire.
• WWW-Authenticate: A response header defining the authentication method.
• Age: Indicates the time (in seconds) the object has been in a proxy cache.
• Pragma: A general header with implementation-specific behavior.
• Warnings: Informs possible problems to the client.
3. Client Hints:
• These headers provide hints to the server based on client capabilities:
– Accept-CH: Specifies which Client Hints headers the client should include in subsequent
requests.
– Accept-CH-Lifetime: Determines the persistence of the Accept-CH header value.
– Content-DPR: Defines the ratio between physical pixels and CSS pixels for selected image
responses.
– DPR: Represents the ratio of physical pixels to CSS pixels in the current window of the
device.
– Device-Memory: Specifies the approximate remaining RAM on the client device.