Sujeet
Sujeet

Reputation: 3810

Many to many resource mapping restful api design

There are many other questions here which target the same problem many-to-many relationship url design for restful apis. I have somewhat the same, but it differs from other.
I couldn't find any better approach.

I have locations resource, and services resource`

GET /services                           //it should give you all services
GET /locations                          //it should give you all locations
GET /locations/:id/services             //it should give you all services offered by a location


The problem that I have is I have to design a route which gives
All locations along with services offered by them

I went though a post on reddit that suggests.
GET /locations?include=services

I also went through another doc . It suggest.
GET /locations-services

I am sure I am not the first one who is having such confusion.
Please help, and if possible share some resources which I can go through to clear my doubts off.

Upvotes: 0

Views: 59

Answers (1)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57214

You can use any spelling you want. You should choose a spelling that is consistent with the spellings you use for other identifiers, for the same reason that we choose spellings of variable names that are consistent with other local variable names.

But

/a1dadfcb-8fc6-4456-b05e-a0b91575e0ef

is a perfectly satisfactory URI.

/locations?include=services
/locations?services
/locations-services
/locations/services
/service-directory

These are all fine. General-purpose components don't care, so long as you use a spelling consistent with the production rules defined by RFC 3986

Upvotes: 1

Related Questions