I guess this is probably a simple question, but I am seeing conflicting answers out there.
I am building a restful web api service that returns class objects. In addition to being able to request ALL items, one item, or category like so:
http://MyService/Category/Blues
I also want to be able to give the users the ability to select multiple, such as:
http://MyService/Albums/12345,77777,87654
http://MyService/Category/Blues,Pop,Metal
I don't need the syntax shown above, that was just an example.
I've already accomplished this by creating code like so:
[Route("Albums/Category/{categoryList}")]
public List<Album> GetAlbumsByCategory(string categoryList)
{
int[] cats = categoryList.Split(',');
return(AlbumManager.GetAlbums(cats));
}
This works fine, but the user needs to know that the input can either be a single value, or a list of values by comma. Then in my AlbumManager I am iterating through the album collection and adding only the selected items to the new list.
I want to know:
(A) Is there already shortcuts in REST and preferred ways of doing this? I have seen some recommendations of Category=Blues&Category=Pop& ..... Seems verbose to me, but if there is a standard out there I want to use it.
(B) When I use my approach, I'm constantly writing split code all over the place. Is there a shortcut in REST for this to simplify? I have seen some [FromUri] references but it's not clear to me.