Search code examples
restrestful-url

RESTful API - how to include id/token/... in each request?


I developed a mobile app that needs to access and update data on a server. I'd like to include e.g. the device ID and some token in each request.

I am including these in the body at the moment, so I have only POST requests, even when asking to read data from the server. However, a request to read data should be GET, but how do I include these pieces of information? Should I just add a body to a GET request? Should I rather add some headers? If so, can I just create any custom headers with any name? Thank you for your guidance.


Solution

  • Your FCM token and device id are really authentication credentials for the request. In HTTP, you typically use the Authorization header with a scheme to indicate to the service

    In your case, you could use bearer tokens in the HTTP Authorization header. While bearer tokens are often used with JWT token, they are not required to be that specific format.

    You could just concatenate the FCM token and the device id like the basic authentication scheme does.

    BTW, it's not recommended to use a body on a GET request since some proxies may not retain that.