RESTful API Design: what about attribute names?
This time, let's talk about what happens when a response comes back.
You have an object with data attributes on it. How should you name the attributes?
Here are API responses from a few leading APIs:
"created_at": Thu Nov 03 05:19;38 +0000 2011"
They each use a different code convention. Although the Twitter approach is familiar to me as a Ruby on Rails developer, I think that Foursquare has the best approach.
How does the API response get back in the code? You parse the response (JSON parser); what comes back populates the Object. It looks like this
var myObject = JSON.parse(response);
timing = myObject.created_at;
timing - myObject.DateTime;
Use JSON as default
- Use medial capitalization (aka CamelCase)
- Use uppercase or lowercase depending on type of object
timing = myObject.createdAt;
Next: What to do when your API returns something other than a resource.