Sending data through the request header versus sending data through the request body

What is the difference between sending data through the request header and sending data through the request body. Under what circumstances should we send data through the header / body, and when should we not send data through the header / body?

+5
source share
2 answers

The body of the message (request) is the one that contains the actual HTTP request data (including form data and downloaded, etc.) and HTTP response data from the server (including files, images, etc.).

While the request header cannot contain actual data, as indicated above. you can use the request header to send a specific header and based on this you can apply your logic. As with creating a rest api, you can send the AUTHENTICATION header to make sure the request is sent from a permitted user or not.

0
source

It is generally recommended to use headers for metadata and bodies for data used by business logic.

Some points to consider:

1) If data is sent via HTTP instead of HTTPS, proxies can change headers.

2) If you use the REST protocol for communication between microservices, communication can be important. Most APIs usually do not provide the ability to add / modify custom headers.

3) It is better to have the data used by routers / firewalls in the HTTP header and limit the body to application-specific information.

0
source

Source: https://habr.com/ru/post/1234508/


All Articles