The result of processing an HTTP request consists of mappings. Each mapping is from an order number to an object. Is it a good practice to return this as an HTTP response whose body is a Map<String, Object>? How about a List where the object contains the order number string as an attribute. If none of these is a good practice, how should the response look like? How are these options, from a RESTfulness perspective?

  • 2
    "Good" in what sense? Specify a criteria. Commented Dec 15, 2020 at 1:23
  • Edited to include a criteria, sort of. Commented Dec 15, 2020 at 2:04

1 Answer 1


the response body for a HTTP request can be whatever you want, really, and how you structure that depends on how your data is structured. If you want it to be easily used by a variety of consumers, converting the data to a common textual data structure is useful.

For this purpose, JSON and XML are common. JSON is probably the closest standard format for what you want. eg, body = {1:{//object}, 2:{//anotherobject}}, with an appropriate content type header (eg, "application/json" so that people using the API know by headers what the format is). I would recommend that over a list of objects with the numeric key eg [{key:1,object:{}}] because the default (val,object) mapping makes it easier to search

Depending on the language you are using, you will probably want to avoid the myMap.toString() type of responses and use a proper/dedicated JSON serialisation function.

Is it good practice? If the data suits the format, it's fine. These sorts of responses are common.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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