REST API – Should a REST Interface Include the Query ID in Responses?

jsonrestweb-api

I am currently working an Android app that receives most of the displayed data from a REST interface.

First, I request the information for a company the request includes a list of store IDs. With each ID I can then request the details for this store.

As part of my app I can update the store opening hours and send them back to the server. For that, I obviously need the store ID to tell the server which store to update.

Now, my question: The JSON object returned by {SERVER}/StoreDetails/{ID} does not include the the store ID. So I need to first fetch the JSON, parse it, and then manually add the store ID to the object – which I feel needlessly complicates my logic, as well as my model objects which now either need a setter of some kind of copy/update constructor when they could otherwise be totally immutable…

Would it be/have been reasonable to include the store ID in the returned JSON object or is that considered redundant and a bad practice?

Best Answer

Sounds perfectly reasonable to me to add the store ID into the payload - as you say, the payload is then more "standalone", and should not need modified after being parsed. Messing with the object to inject a field that you could trivially include when building the response feels wrong to me.

Related Topic