News for hackers. Stuff that matters.
Re:REST worst practices by wmf on Friday January 20, 2012 @05:33PM (#3491527)
In REST there is no need for IDs at all. There is only URLs; the URL of an object is the only way to refer to it.
Re:REST worst practices by sashthebash on Friday January 20, 2012 @06:07PM (#3491650)
I almost completely agree, but a problem I often encounter in REST API design is: how to do searches?

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?

Re:REST worst practices by icebraining on Friday January 20, 2012 @06:39PM (#3491812)
Why use GET instead of POST? Just POST a document with the parameters to filter, and the server creates a new resource with the search results and returns its URL to the client, which can then GET it.
Re:REST worst practices by boucher on Friday January 20, 2012 @07:08PM (#3491919)
There's really no need to create a separate URL; it's reasonable for POST requests to contain response bodies.
Re:REST worst practices by bct on Friday January 20, 2012 @06:59PM (#3491880)
I don't think there's anything particularly unRESTful about using non-URL ids in that case. The critical thing is that the client isn't using out-of-band knowledge (i.e. what the developer read in the API documentation and hardcoded into the client) to construct the query.
Re:REST worst practices by rue on Friday January 20, 2012 @05:49PM (#3491579)
URLs, and links. And, more precisely, an URL is the only way to refer to a resource. There may be multiple URLs pointing to the same.

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.