• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the logical structure of a REST API URI to get all child resources of a parent resource

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a rest api for a small project I'm doing. It's a buy and sell website. But I'm wondering how I should go about structuring the URI's

I'm going to have 2 main resources - users and ads. Where a user can create a number of ads. I'm presuming that if I wanted to create an ad for a specific user the uri would look something like this.


But what would the uri be if I wanted to get all ads irrespective of user. What would that look like.

Would it be one of the following or something else?

?

?

Any input would be appreciated.

Thanks
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Definitely /api/ads.

I challenge the notion that an ad is a sub-resource of a user. An ad is associated with a user, but neither of the two is an obvious parent of the other.

To create a new ad, you'd make the following request:

The user ID is determined either from the current login, or sent in the request body.


You can use the following request to get the user that created an ad:

You can use the following request to get all ads that a user created:

But neither of those two paths are appropriate for posting new records to.
 
Bryan Cartys
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's great. Thank You.
That's how I've it written. But after doing it I was second guessing myself.

Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic