Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST API best practice - where to place a unique request identifier

When designing a REST API, what is the best practice for adding a unique request identifier when performing an http request?

I would normally add it in the headers as x-request-id, but today heard someone mention adding it in the url as a query string!

Also after doing some research, it seems like some people add it in the response body and send it as part of the payload!

Out of these three which would be the best application of a unique request identifier and why? What are the possible pros and cons of each approach?

like image 899
hyprstack Avatar asked Jul 16 '18 13:07

hyprstack


People also ask

What is a good practice that should be followed for a REST API Select 2?

REST API Best Practices: Always choose JSON One of the important best practices to follow is to always choose JSON. The key feature of JSON is that it is very easy to parse and supports most frameworks. JSON can be used by any programming language.

What is identifier in REST API?

Each REST API resource can be accessed by using a Uniform Resource Identifier (URI). The URI must contain the correct connection information to successfully call the API. The connection information consists of the host name where the web management service is running, and the port number that the service is using.


1 Answers

HTTP doesn't include any request identifiers.

However, if you need one (for debugging or log enhancements, for example), you could use a header of your choice. Headers such as X-Request-Id, X-Correlation-Id and X-Trace-Id look fine for the scenario described in your comment: track a request through multiple requests in an internal micro-service architecture.

The value of such header could be an UUID.


This article will probably give you some insights. Also have a look at Zipkin.

like image 64
cassiomolin Avatar answered Oct 14 '22 07:10

cassiomolin