Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Nested resources best practices (WebAPI, REST)

$
0
0

How should I design the API like:

/player/5/items/

Should I define the GetPlayerItems method inside PlayerController and setup routing there or define it in ItemController?

if I do it in PlayerController, I have to inject 2 different repositories, services (with onion architecture), however the naming seems more appropriate to do it inside PlayerController

[Produces("application/json")]
[Route("api/[controller]")]
public class PlayerController
{
    ...
	[HttpGet("{id}/Items")]
	public async Task<IEnumerable<Item>> GetItems(int id)
	{
	    // get items by player id 
	}
}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>