Many to many resource mapping restful api design

Sujeet Agrahari

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.

VoiceOfUnreason

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

RESTful API Design: PUT or POST for creating many-to-many relationships?

How to design this mapping (many:many) in MongoDB?

many-to-many relationships with fields in a RESTful API

Many tables for api restful Spring

JPA many to many mapping

Automapper many to many mapping

Many to Many Mapping / Seed

How to create or update a many to many relationship with a RESTful API

How to handle many-to-many relationships in a RESTful API?

How to create/update many-to-many relationships in a RESTful API

many functions in one middleware expressjs restful api

.Net Core API & Automapper with many to many relationship mapping

Laravel API Resource With Many-to-many Relation Causes Error

EF Core Many to Many using Automapper returns loop on API Resource

Hibernate query on many to many mapping

Querying many to many mapping in ElasticSearch

Automapper many to many mapping confusion

Many to Many mapping objects in javascript

Design a RESTful api for creating a resource and its related resources at once

Rails: Many to many database design

Laravel Schema design many to many

Loading many base64 images from RESTful API

Golang RESTful API load testing causing too many database connections

Securing Registration RESTful API against registering many users

AutoMapper - one to many mapping

Bidirectional Many to One Mapping

How can i retrieve data from many to many, for create my custom restful api on laravel?

What's the "right" way to create a many-to-many relationship in a Restful API

API RESTful Laravel 6.x Best Practice for Many to Many Relatioship