I understood (I think...) the basics of REST but while trying to design my API I got a little confused with sub-resources, I'll try to explain with an example:
lets say I have an application that has two resources, users and rooms, a user can create rooms and join rooms, is the following REST URIs correct ?
or should it be something like /users/< userId >/rooms/joined or /users/< userId >/rooms?query=joined ?
also how would "get similar rooms" URI would look like ? /rooms/< roomId >/similar or /rooms/?query=similar ?
URL design is an art form, not a REST constraint. REST says nothing about what your URLs should look like. URLs are opaque strings and their contents is irrelevant.
/users/<userID>/joinedRooms/users/<userID>/rooms/joined/users/<userID>/rooms?query=joinedAny of these options you have suggested are equally valid. Pick whichever one works best for you, as long as it represents a resource.
also how would "get similar rooms" URI would look like
Again, whatever you want. How about /yaz1-oPhce6~X_? :-)
When making your decision, I suggest you try to factor in things like ease of implementation, aesthetics, and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With