0

I wonder if in REST is right return a response in square format instead of curly brackets.

For example, is rigth nex example?:

[
  {"code":code,
   "value":value},
  {"code":code,
   "value":value}
  ...
]

Or always our response must be in curly brackets:

{
 "key":[ -- thanks milgner
  {"code":code,
   "value":value},
  {"code":code,
   "value":value}
  ...
 ]
}
HeyYou
  • 21
  • 4
  • Both are valid if they are valid JSON. It really depends on what your clients need. In fact you can support both formats if you want to. – inf3rno May 17 '21 at 09:34

1 Answers1

1

The second version isn't valid JSON (missing a key name for the array) so it would be an incorrect response. Apart from that, REST doesn't say anything about the exact format of the response. Doesn't even need to be JSON: a XML-based response format or even other formats like msgpack, or even HTML (hypermedia!) would be fine, too.

Marcus Ilgner
  • 6,935
  • 2
  • 30
  • 44