I have several methods that I want to use for their URLs.
Mostly there are restaurants that have ID cards, and a collection of terminals below them.
I'm trying to create the following kind of template: api / Restaurant - get all restaurants api / Restaurant / Bobs - get a restaurant with Bob ID api / Restaurant / Bobs / terminal - get all terminals in a restaurant bobs api / Restaurant / bobs / terminal / second - get terminal with the identifier of the second in the bob restaurant
I have methods for this, and I assigned each Route attribute the following:
[HttpGet]
public IEnumerable<IRestaurant> Get()
{
}
[HttpGet]
[Route("api/Restaurant/{restuarantName}")]
public IRestaurant Get(string restaurantName)
{
}
[HttpGet]
[Route("api/restuarant/{restaurantName}/terminals")]
public IEnumerable<IMiseTerminalDevice> GetDevices(string restaurantName)
{
}
[HttpGet]
[Route("api/restaurant/{restaurantName}/terminals/{terminalName}")]
public IMiseTerminalDevice GetDeviceByName(string restaurantName, string terminalName)
{
}
However, only my main GET (api / Restaurant) works. My default webapi configuration and read
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
- , ? ( ) 404.
!