2

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?

2

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.

  • Thank you! A follow up question: I just noticed that to update (PUT) an employee I must provide (in addition to the employee ID) the store ID of this employee. However, the only way to GET employee objects is as part of the store information, and the JSON of the employee does contain neither employee ID nor store ID. As you said, it would be reasonable to expect the employee ID - but could I also expect the store ID in the employee object. Or, more generally, should the response objects contain all the information (IDs) that is needed to later update the same object on the server? – david.mihola Apr 29 '14 at 12:29
  • It may be helpful to draw some diagrams to map out the flow of your operations. That may make it clearer where you could cut out a request by including more information in a response. In general, I would expect an extra request to the server to take much longer than including a few extra fields in a response. – Rory Hunter Apr 29 '14 at 12:49
  • Unfortunately, I don't have any control over the API itself. My questions are more concerned with what is or would have been good design. I am having some problems with the provided REST interface but being a novice myself I am unsure whether these problems are due to my inexperience or due to careless design of the interface... With respect to the store/employee IDs: The structure is fine as long as it is handled top-down - but when I start editing an employee and then need the parent store I run into trouble. I guess I will have to always track the store ID, when I handle employees... – david.mihola Apr 29 '14 at 13:02
1

Have a look a this ressource: http://jsonapi.org/format/#document-sigular-resources. When you follow this standard you have to include the id of the store in your json.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.