Skip to content

Instantly share code, notes, and snippets.

@dadamssg
Last active December 29, 2015 03:08
Show Gist options
  • Save dadamssg/7605129 to your computer and use it in GitHub Desktop.
Save dadamssg/7605129 to your computer and use it in GitHub Desktop.
//Why are collections namespaced and single entity responses not? For example:
[
{
"name": "Hulk Hogan",
"id": "100002"
},
{
"name": "Mick Foley",
"id": "100003"
}
]
//the above seems more consistent with the following
{
"name": "Phil Sturgeon",
"id": "511501255"
}
//or provide the resource type with the single entity response as well
{
"users": [
{
"name": "Hulk Hogan",
"id": "100002"
},
{
"name": "Mick Foley",
"id": "100003"
}
]
}
//single entity response
{
"user": {
"name": "Hulk Hogan",
"id": "100002"
}
}
@philsturgeon
Copy link

I do not namespace a single resource because there is only one thing it could possibly be: the resource you asked for.

I namespace collections because you can have pagination and other meta data in there.

But you can do whatever you like. :)

@dadamssg
Copy link
Author

@philsturgeon thanks. that makes sense. I was going to bring up the possibility of meta data being returned but i can't think of any meta data that would make sense to return with a single entity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment