Hacker News new | ask | show | jobs
by digitallimit0 5233 days ago
In terms of a RESTful web service, is an object's id supposed to be passed in as a parameter in a GET request, or be a part of the core URI, e.g. api.test.com/teacher/1234 would retrieve the teacher of id=1234 or api.test.com/students/1234 would retrieve that teacher's students.

Is api.test.com/teacher?id=1234 more kosher?

2 comments

The pattern used in Rails would be something like api.test.com/teacher/1234/students
I was just reading up on the Graph API Facebook uses and its pattern is just api.test.com/1234/students. There seems to be very little standardization. The tutorial I'm reading right now wants me to pass the id in as a parameter. Weird.
Facebook's REST APIs seem pretty casually designed. "api.test.com/students/1234" is better URL design than "api.test.com/1234/students". You could then naturally guess to use "api.test.com/students" to get a list of students whereas with "api.test.com/1234/students" you'd end up having to do something weird like "api.test.com/all/students".
api.test.com/students/1234 would be correct. A REST URL is supposed to identify a resource (noun) when possible.