Answer the question
In order to leave comments, you need to log in
How to organize access to resources in REST API?
I am developing a media service REST API. Media is audio (music bands, albums, tracks...) and video (movies, series, seasons, episodes...). All media in the database are stored in one table - Media. In the API for each media type, I decided to use several endpoints:
/movies/
/music-groups/{id}/albums/{id}/tracks/{id}
и т.д.
Answer the question
In order to leave comments, you need to log in
Too smart. Everything should be very simple. What is a media type? Music or video? So by
/movies/genre/{id}/film/{id} - movies
/music/albums/{id}/tracks/{id} - music
music/getalbums/1456 - get all albums of an artist
music/detailalbum/1456 - get all data about an album (year of release, etc.)
music/tracksalbum/1456 - get a list of tracks of a particular album
In general, do not go from the particular to the general, but vice versa, imagine where to start work for a person who knows nothing. Enter the maximum atomicity of queries so that they are not related to each other in any way. And a person will first receive jarni, by genre a list of performers, by him a list of albums, by him a list of songs, by him data about the desired song. And these are all separate requests.
Somehow it is not clear: usually methods (analogues: create, set, get, update, delete, etc.) are taken out (mounted) on the entry points of client requests (endpoint).
All parameters passed to the method are already POST JSON (in most cases).
There are also exceptions when the methods are simple and the parameters go in the endpoint address, but then the address should return WITHOUT redirects and the server should correctly "understand" this request, because in fact, this is already a search query that is not related to RESTful.
e.g. the user liked the music track, he follows the link /media/{track_id}, and he is redirected to /music-groups/{mg_id}/albums/{a_id}/tracks/{track_id}We do not change the address (without a redirect!), but we can return extended information about the track, group, album in the form of a structure (an array or a tree) in the response.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question