Sobes.tech
Junior

What are entity headers?

sobes.tech AI

Answer from AI

Entity headers in HTTP contain meta-information about the resource or message body transmitted in a request or response. They describe the content but not the resource itself.

Main entity headers:

  • Content-Type: Indicates the media type (MIME type) of the message body, for example application/json, text/html, image/png.
  • Content-Length: The size of the message body in octets (bytes).
  • Content-Encoding: The encoding (compression) method applied to the message body, for example gzip, deflate.
  • Content-Language: The natural language of the content, for example ru, en-US.
  • Content-Location: An alternative location of the resource.
  • Expires: The date/time after which the content is considered stale.
  • Last-Modified: The date/time of the last modification of the resource.
  • ETag: A unique identifier for the version of the resource (often a hash of the content).

Examples of usage in request and response:

Request (with body):

POST /api/users
Host: example.com
Content-Type: application/json
Content-Length: 31

{
  "username": "john.doe",
  "email": "john@example.com"
}

Response (with body):

HTTP/1.1 201 Created
Content-Type: application/json
Content-Length: 50
ETag: "abcdef123456"
Expires: Tue, 05 Dec 2023 12:00:00 GMT

{
  "id": 123,
  "username": "john.doe",
  "email": "john@example.com"
}

They are used for proper processing and interpretation of the message body by the client and server, as well as for caching and conditional requests.