Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Restful service URL  RSS feed

Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a rest webservice built on restlets(NOTE).
Most of the requests are GET request for URL resources.

However,we face a situation where the URL nodes may not be well-defined viz. /book/{book_id}/author/{author_id}/topic/{topic_id} and /book/{book_id}/topic/{topic_id} could both be valid URL.

What be the ideal design to handle such a scenario with resource handlers.
We wish to avoid query parameters as far as possible.
Ivan Krizsan
Ranch Hand
Posts: 2198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that trying to look at the situation from another angle may help you.
First of all a question: In what situations are the resource URIs not well defined?
A provoking statement: The resource URIs never need to be "well defined".
Because if the service always provide the resource URIs, then the clients only need to use the provided URIs.
This also has the advantage of reducing the coupling between service and clients.

To obtain a list of available books, the client accesses the URI /book/
The result is a list of entries in which each entry provide an URI for the book in question, for instance /book/12345
To retrieve information about the specific book, the client accesses the appropriate URI from the previous result.
On receiving information about the book, the fields in the book data structure which contain more/complex information provide an URI where further details can be obtained, for instance author.
The book at /book/12345 may contain two author entries, /book/12345/author/1111 and /book/12345/author/2222.
To obtain more information on the second author, the client follows the supplied URI, that is /book/12345/author/2222.

Using this method, you can allow a client to navigate from any starting point, in the above example the books, to a specific resource, author, related to a book.
When starting, the client knows only a minimum of how the resources are organized, as far as URIs are concerned. In fact, the less the client knows in this area, the better.
The above only touches this topic very briefly, but I hope it is of help.
Best wishes!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!