Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST: HTTP headers or request parameters

I've been putting in some research around REST. I noticed that the Amazon S3 API uses mainly http headers for their REST interface. This was a surprise to me, since I assumed that the interface would work mainly off request parameters.

My question is this: Should I develop my REST interface using mainly http headers, or should I be using request parameters?

like image 613
Gevious Avatar asked Oct 30 '11 12:10

Gevious


People also ask

What is the difference between header and parameter in REST API?

Headers carry meta info, parameters carry actual data. HTTP Servers will automatically un-escape/decode parameter names/values. This does not apply to header names/values. Header names/values need to be manually escaped/encoded at client side and be manually un-escaped/decoded at server side.

What is header parameter in REST API?

The REST headers and parameters contain a wealth of information that can help you track down issues when you encounter them. HTTP Headers are an important part of the API request and response as they represent the meta-data associated with the API request and response.

What is request parameter in REST API?

API Parameters are options that can be passed with the endpoint to influence the response. In GET requests, they're found in strings at the end of the API URL path. In POST requests, they're found in the POST body.

When should I use HTTP headers?

The HTTP headers are used to pass additional information between the clients and the server through the request and response header. All the headers are case-insensitive, headers fields are separated by colon, key-value pairs in clear-text string format.


1 Answers

The question mainly is whether the parameters defined are part of the resource identifier (URI) or not. if so, then you would use the request parameters otherwise HTTP custom headers. For example, passing the id of the album in a music gallery must be part of the URI.

Remember, for example /employee/id/45 (Or /employee?id=45, REST does not have a prejudice against query string parameters or for clean slash separated URIs) identifies one resource. Now you could use content-negotiation by sending request header content-type: text/plain or content-type: image/jpg to get the info or the image. In this respect, resource is deemed to be the same and header only used to define format of the resource.

Generally, I am not a big fan of HTTP custom headers. This usually assumes the client to have a prior knowledge of the server implementation (not discoverable through natural HTTP means, i.e. hypermedia) which always is considered a REST anti-pattern

HTTP headers usually define aspects of HTTP orthogonal to what is to be achieved in the process of request/response. Authorization header (really a misnomer, should have been authentication) is a classic example.

like image 116
Aliostad Avatar answered Sep 22 '22 11:09

Aliostad