/contacts[ {"id":1,"address":123,"city":"London"}, {"id":2,"address":"456","city":"New York"} ...]/contacts/3 {"id":3,"address":123,"city":"London"}For unsuccessful responses, I have the following (this allows me to show more than 1 error message if necessary):
{"errors":["Invalid public key credentials"]}
Extra meta information (such as rate limit, pagination and http code) are returned in the header.
I know that there is no "right" way, but having seen so many different implementations, I'd like to know if this doesn't fall foul of accepted best practice. Am I missing anything super obvious here?
Many thanks for any input that you can give.--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group, send email to api-craft+...@googlegroups.com.
Visit this group at http://groups.google.com/group/api-craft?hl=en.
On Success:{"code": 200,"status": "success","data": [
{"id":1,"address":123,"city":"London"},
{"id":2,"address":"456","city":"New York"}
...
]}
On Error:{"code": 401,"status": "error","message": "Invalid public key credentials","data": "bad-credentials",}
I don't like this approach. It obscures the most important parts of the representation with information that is best handled in the HTTP layer. Most HTTP libs these days are not broken and therefore allow easy access to the header info.
If you really do have clients that are not able to access the response codes I'd prefer tucking that info away in a corner so that clients with less brain damage can ignore it. For example,
{
"address": "123 ...",
// rest of data
"_resp_metadata": {
// for clients that use borked HTTP libs
"code": 200,
"status": "success"
}
Peter
Barelyenough.org
Thanks for the reply Mike. I see a lot of value in that kind of response, although there is an argument that the code and status could be included in the header.
I don't like this approach. It obscures the most important parts of the representation with information that is best handled in the HTTP layer. Most HTTP libs these days are not broken and therefore allow easy access to the header info.
If you watch the video[1] you'll see that Todd addresses the need around 4:30 saying that in jQuery AJAX you can't read the status code nor headers and he had at least one person in the audience agree that it is a problem.I post his example to the list because it seemed that others on this and the prior thread were collecting different approaches and I felt his approach had merit to be added to the list.
If you really do have clients that are not able to access the response codes I'd prefer tucking that info away in a corner so that clients with less brain damage can ignore it. For example,
{
"address": "123 ...",
// rest of data
"_resp_metadata": {
// for clients that use borked HTTP libs
"code": 200,
"status": "success"
}
I prefer Todd's approach because it puts the meta at the top level and then "real data" in the "data" property. Nothing obscures the real data and if you just want the pure data you can easily grab just it. Not so if there is an embedded "_resp_metadata" or otherwise named property. FWIW.
--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group, send email to api-craft+unsubscribe@googlegroups.com.