14 Tweets 29 reads Jul 25, 2022
10 HTTP Headers every API developer should be aware of:
Thread ๐Ÿงต
Client and server can pass the extra bit of information with the request and response using HTTP headers.
HTTP headers are not case-sensitive.
The HTTP headers are divided into four categories:
1๏ธโƒฃ Request headers: Client to Server
2๏ธโƒฃ Response headers: Server to Client
3๏ธโƒฃ Representation headers: Information about the body of the resource
4๏ธโƒฃ Payload headers: Information about the payload data
๐Ÿ“Œ Accept
`Accept` header is used when the client wants to inform the server about the data type the client can understand.
For example,
Accept: image/png
๐Ÿ“Œ Accept-Encoding
The `Accept-Encoding` header is usually attached with a request to the server, indicating which encoding method is understandable by the client.
For example,
Accept-Encoding: gzip
๐Ÿ“Œ Authorization
As the header name suggests, the `Authorization` request header is used to pass the credentials so the server can authenticate the client.
For example,
Authorization: Basic dgfhWUytzgdfhgSYG
๐Ÿ“Œ Accept-Language
The `Accept-Language` request header is used to describe the language the client understands.
For example,
Accept-Language: en-US
๐Ÿ“Œ Content-Type
`Content-Type` representational header specifies the media type of the resource. This header indicates the content type of the returned data when the client didn't mention any content encoding.
For example,
Content-Type: text/html; charset=UTF-8
๐Ÿ“Œ Content-Location
`Content-Location` header indicates the alternate location for the response. It is used when an API can return data in different formats depending on the `Accept` header.
For example,
Content-Location: /examples/foo.json
Content-Location: /examples/foo.xml
๐Ÿ“Œ Content-Encoding
The `Content-Encoding` header compresses the message data or payload.
For example,
Content-Encoding: gzip
๐Ÿ“Œ Content-Length
As the header name suggests, it indicates the resource or message body size in bytes. It can be used with both requests and responses.
For example,
Content-Length: 148
๐Ÿ“Œ Content-Language
`Content-Language` indicates the human logical language of the response. This header is used to deliver resources in multiple languages so that users can choose their preferred language.
For example,
Content-Language: en-US
๐Ÿ“Œ Cache-Control
`Cache-Control` header is used as a caching mechanism for both the request and response.
We can pass several directives(values) with this header.
For example,
Cache-Control: max-age
With that said, this is pretty much it for this thread.
Follow @Rapid_API for more quality content related to API development. ๐Ÿš€

Loading suggestions...