My personal best practice would be to build batching facilities for your APIs. Batching is incredibly important when your application data grows.
My personal best practice would be to build batching facilities for your APIs. Batching is incredibly important when your application data grows.
The point is that REST uses Hypertext as the Engine of Application State. You might have heard of this as HATEOAS.
Ideally, your API is discoverable given the initial URL. If you return IDs, I have to construct URLs based on information I already have. If you return URLs, I just have to make an HTTP request.
I've not thought much about this but Roy Fielding disagrees [1].
[1] http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hyperte...
Aside what appared to be a fundamental misunderstanding on the GP's part, there is the legitimate concern that an individual resource shouldn't need to know its own URL. In the article, that was just glossed over, though.
One could, for example, have a book by ID 1 trickle the ID up the application call path, and at a higher level, a complete URL is generated. In fact, the application could simply be a module inside yet another one that wants to add its own ‘namespace’.
What the URL is and how it's generated doesn't matter. All that does is that the URL is made available (discoverable), and that it goes to the right resource, however that happens.
Let's say we have an "Event" Resource and it belongs to a "Location" Resource and the Event belongs to "Category" Resources. If you want to provide an endpoint to search events with a GET requests and filter based on Location and Categories (which are identified by URLs) you can end up with really long query strings.
/events?location=URL1&categories[]=URL2&categories[]=URL3&categories[]=URL4&...
This is not only ugly, it can bring up problems on both clients and servers.
Any suggestions on how to handle this?
Can you explain a bit more? I'm just surprised because returning URLs (not IDs) is a fundamental idea of proper REST.
In particular, my doubts about IDs vs URLs is the ability to store those pieces of data in the client (or intermediate caches) - if the service URLs or namespaces change, the client-side URLs become useless even after the client updates the service entry point. With IDs, that information would still be usable.
I'm absolutely no expert on this so I'm probably in the "HTTP API, not REST API" side of the problem.
Same concept as deprecating code. You don't wipe it out straight away because you have no idea what else might rely on it or how fast they are to react (within reason).
As for the arguments about not using HTTP request methods - they're standard, and are implemented uniformly everywhere (for the best part). Your API isn't standard, but if all APIs use HTTP and its request methods correctly, you only need to learn the general HTTP spec to generally understand all APIs.
Resources and URL structure afterwards is a matter of opinion. What may seem RESTful to me might not be to someone else.
One other semantic nitpick is that a URL is a subset of URI, which stands for Universal Resource Identifier, so in some sense you could make a philosophical argument that URI and IDs are/should be the same thing. If you were really crazy you could store URLs in your DB (obviously not a good idea for many other reasons).
Which is OK, because the client can re-traverse the service to get back to those resources which are now invalid.