HTTP headers are key-value pairs included in HTTP requests and responses that provide metadata
about the message.
Even though you can use body for everything, it is a good idea to use headers
for sending data that isnβt directly related with the application logic
.
For example, if you want to create a new TODO, you will send the TODO payload in the body
{
description: "Go to gym"
}
But the Authorization
information in the headers
Authorization: harkirat
Because headers and body serve different purposes.
Header | Body |
---|---|
π’ Meta info about the request | π¦ Actual data or content |
Used by server to understand how to handle the request | Used by server to process the actual data (e.g. form, JSON) |
http
CopyEdit
Authorization: Bearer eyJhbGci...