Search code examples
resthttphttp-headersapi-design

Is there an appropriate header for sending client library information in a REST Api?


I would like to send an identifier of my client libraries when calling my RESTful API. We have client libraries for Java, C#, Ruby, Python and others. For example, my Java client library could send:

User-Agent: java/1.10.2

Is it better to use the User-Agent header or a custom header just for my application? The User-Agent header seems to be used more for browsers, and I am yet to find an API that uses the header for client libraries.

EDIT

  1. The client library is used by our customers to consume our API and it handles all the request and response logic. It's just an easy way of calling our API.
  2. The information will be used just for statistics and to help us identify which version of the client library our customers are using in the event of a bug.

Solution

  • I think User-Agent is the appropriate header in this scenario.

    According to Wikipedia, User-Agent is:

    a user agent is software (a software agent) that is acting on behalf of a user... In many cases, a user agent acts as a client in a network protocol used in communications within a client–server distributed computing system. In particular, the Hypertext Transfer Protocol (HTTP) identifies the client software originating the request, using a user-agent header, even when the client is not operated by a user.

    Thus, to become a User-Agent, it should be:

    1. a software
    2. client in a network protocol
    3. on behalf of a user

    According to the description in question, the client library (software) is used to consume API (on behalf of a user) and handles ALL the request & response logic (client in a network protocol), which makes it perfectly follow the above definition.

    Also, the usage of client library information is typically what plain browser's User-Agent is used for.