I feel as if i am over-thinking this, but with a RESTful API design with resources being themselves resources of something how should these 'typically' be accessed?
Of course, an acceptable answer is 'it depends', but i am trying to understand what is usually what people might expect, and then also what is easiest to reason about during implementaiton.
An example, we have houses and rooms within those houses..
Fetch all the houses, or get a single specific house info:
GET ../v1/houses <--- [] of house info
GET ../v1/houses/{houseId} <--- specific house info
So far so good, then if i want all the rooms regardless of house, a specific known room, or all the rooms of a specific type:
GET ../v1/rooms <--- [] of all rooms, users current want this
GET ../v1/rooms/{roomId} <--- specific room, implicitly in a specific house
GET ../v1/rooms?roomType=bathroom <--- all bathrooms in all houses
Q: If these are implicitly part of a house (and you cannot reasonably have a room without a house) should they also return information about the "parent" resource too? I think yes.
If however a user wants all the rooms in a specific house should we do a)
GET ../v1/houses/{houseId}/rooms <--- sub-resource room info
or require two-step b)
GET ../v1/houses/{houseId} <--- get detail of the house inc. roomId values
GET ../v1/rooms/{roomId} <--- query them all
or even filter c)
GET ../v1/rooms?houseId={houseId}
Q: You can't pass a body with a GET
, so which is the most acceptable solution?
Q: Bonus points for what to really do when needing all the rooms across more than a single house. This feels very non-RESTful:
GET ../v1/rooms?houseId={houseId},{houseId}
GET ../v1/rooms?houseId={houseId},{houseId}&?roomType=kitchen
I guess this could be one of those situations whereby it's your own preference, but happy to hear other peoples thoughts?
Ty.