I am in the process of setting up my first apigility project and so far it is going well. I'm having some issues with the routing and how to set it up though.
Suppose I have songs, albums and artist (fictitious example for this question only). I want to do a structure like this:
/artists (GET, POST, PUT, PATCH, DELETE)
/albums (GET, POST, PUT, PATCH, DELETE)
/songs (GET, POST, PUT, PATCH, DELETE)
Pretty easy so far. I have filters on those end-points so I can say:
/artists/?style=jazz
/albums/?year=2012
etc...
Now, I also want to include child end-points like this:
/artist/12345/albums (GET) - get all albums for artists with id 12345
/artist/12345/songs (GET) - get all songs for artists with id 12345
/albums/98765/songs (GET) - get all songs for album with id 98765
How do I set this up in a proper way in apigility?
I started by creating a separate service ArtistAlbum, with route /artists/:artist_id/albums and then changing the entity from ArtistAlbumEntity to AlbumEntity (it is basically that) and the collection from ArtistAlbumCollection to AlbumCollection. The route identifier name is set to artist_album_id though, which I will never use. You cannot delete that though.
This ways feels a bit hacky to be honest.
In effect, the above route /artists/:artist_id/albums is actually an alias for /albums/?artist_id=:artist_id. It is a sort of filter.
How do I implement something like this in a proper way?