Quantcast
Channel: User LuckyLuke - Stack Overflow
Viewing all articles
Browse latest Browse all 37

URIs for composite objects in RESTful web service

$
0
0

I have created the paths:

POST /books/4/chapters 

The Chapter entity is part of the Book composition. It can not exist in the system without a book. Now after creating a chapter by posting to the URI above, should I create another set of URIs for the answer resource for updating and getting a particular chapter?

GET /books/4/chapters/6 or GET /chapters/6?

Remember that once you have the primary key for one level, you usually don't need to include the levels above because you've already got your specific object. In other words, you shouldn't need too many cases where a URL is deeper than what we have above /resource/identifier/resource.

From apigee Web API Design

This GET /chapters/6 would be more true to what the article says, however that also means that you object is not in scope of its parent anymore (since it is part of a composite object of class Book). However I feel that this is better since chapters could be a composition of other objects again meaning that you get long nested URIs

GET /books/4/chapters/5/paragrahps/5 if everything should be in scope of the parent.

What would be the preferred way of doing this

Edit

After more thinking it probably will be the best to have URIs like /books/4/chapters/9 etc since you don't have repositories etc in the code for retrieving a particular feedback without its parent because it is a composite?


Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>