json - Map or Array for RESTful design of finite, unordered collection? -


a coworker , in heated debate regarding design of rest service. of our api, calls collections return this:

get /resource [     { "id": 1, ... },     { "id": 2, ... },     { "id": 3, ... },     ... ] 

we must implement call collection of properties identifying attribute "name" (not "id" in example above). furthermore, there finite set of properties , order in sent never matter. spec came looks this:

get /properties [     { "name": "{property_name}", "value": "{property_value}", "description": "{property_description}" },     { "name": "{property_name}", "value": "{property_value}", "description": "{property_description}" },     { "name": "{property_name}", "value": "{property_value}", "description": "{property_description}" },     ... ] 

my coworker thinks should map:

get /properties {     "{property_name}": { "value": "{property_value}", "description": "{property_description}" },     "{property_name}": { "value": "{property_value}", "description": "{property_description}" },     "{property_name}": { "value": "{property_value}", "description": "{property_description}" },     ... } 

i cite consistency rest of api reason format response collection way, while cites particular collection finite , order not matter. question is, design best adheres restful design , why?

iirc how return properties of resource not matter in restful approach.

http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

from api client point of view prefer solution, considering explicitly stating name of property xyz.

whereas coworkers solution imply name, how know sure (without reading api documenation). try not assume regarding consuming clients, because know means (and easy enough assume means) might not obvious clients.

and on top of that, break consuming clients if ever decide revert value being name id. in case have done in past. clients need change code, whereas not have in solution, unless need newly added id (or other property).


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -