I have multiple actions in the controller of my API. They mean to retrieve a bunch of data relating the models, So all of them are [HttpGet]
type. How to resolve multiple endpoints error?
[HttpGet("{genreName}")]
public IActionResult GetMoviesByGenre(string genreName)
{
var movies = _applicationDbContext.Movies.Where(m => m.Genres.Any(g => g.Name == genreName)).ToList();
if (string.IsNullOrWhiteSpace(genreName))
return NotFound();
return Ok(movies);
}
[HttpGet("{directorName}")]
public IActionResult GetMoviesOfADirector(string directorName)
{
var movies = _applicationDbContext.Movies.Where(m => m.Director.Name.Contains(directorName)).ToList();
if (string.IsNullOrEmpty(directorName))
return NotFound();
return Ok(movies);
}
You could try to create two controllers like DirectorController.cs and GenreController and You can have endpoints like:
api/Director/{directorName}/Movies
api/Genre/{GenreName}/Movies
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.