I am trying to set up a API for my MVC web app that will have a lot of routes but much of the same part for each one. Basically a CRUD for each area. I am also setting it up t
Example with Action name dynamically:
[Route("api/{lang}/[controller]/[Action]")]
[ApiController]
public class SpatiaController : ControllerBase
{
private readonly ISpatialService _service;
private readonly ILogger _logger;
public SpatialUnitsIGMEController(ILogger logger, ISpatialService service)
{
_service = service;
_logger = logger;
}
[HttpGet]
public async Task>> Get50k(string lang)
{
var result = await _service.GetAll50k(lang);
return Ok(result);
}
[HttpGet("{name}")]
public async Task> Get50k(string lang, string name)
{
var result = await _service.Get50k(lang, name);
return Ok(result);
}
}
To call these endpoints the following calls would be used:
https://example.domain.com/api/en/spatial/get50k --> we get all the data in English
https://example.domain.com/api/en/spatial/get50k/madrid --> we obtain the data of madrid in english
https://example.domain.com/api/es/spatial/get50k/madrid --> we obtain the data of madrid in spanish
(using the action and language in the route)