It is better to create a RESTful API first in terms of resources rather than a URI. This has more to do with your data design than, say, your choice of language.
For example, you have a Distribution resource. You want to present it in your web interface, so it must have a corresponding unique resource identifier (URI). It should be simple, readable and unlikely to change. This would be a worthy example:
http://example.com/api/distribution/<some_unique_id>
Think twice before investing more things and hierarchies in your URIs .
You do not want to change your URIs as your data model or authentication scheme is evolving. Changing the uncool URI is a pain for you and the developers who use your API. Thus, if you need to authenticate with the backend, you should probably use GET parameters or HTTP headers (for example, the AWS S3 API allows both ).
Enabling too many GET parameters (e.g. http://example.com/api/distribution/?id=<some_unique_id> ) may sound like a bad idea, but IMO doesn't really matter [0] - while you keep your documentation The API is accessible and relevant.
[0] Update: for the read-only API, at least. For the CRUD API, as @daniel noted, this is more convenient when you have endpoints, as in the first example above. Thus, you can make good use of HTTP methods by including GET, PUT, DELETE for individual resources in /api/distribution/<id> and POST for /api/distribution to create new distributions.
While researching the answer, I found a nice presentation about the RESTful API: Designing HTTP Interfaces and RESTful Web Services .
Tony
source share