resttastypie

Handling nested URI's in tastypie


I am building a REST API in which unique objects are owned by users. So URI's need (project requirement) to be formatted like so:

/api/v1/user/[user_slug]/book/[book_isbn]

example:

http://library.edu/api/v1/user/jack@gmail.com/book/1481879707

or

http://library.edu/api/v1/user/jill@gmail.com/book/1481879707 

Both are unique objects

How do I use tastypie to do this?


Solution

  • I think you need to write a prepend_urls method in your resource, just as said in this section of Tastypie doc:

    Tastypie Doc - Cookbook#nested-resources

    Instead of Children you'll have your Books resource and you also will change to fit on your URL pattern.