Reputation: 397
I am trying to create below structure in ASP.Net Web Api 2
https://<host>/api/webhooks/incoming/custom
I can navigate to webhooks by creating controller webhooks but how can I create the other two underneath it?
Any idea on this please?
Upvotes: 0
Views: 183
Reputation: 16801
You could do this with attribute routing.
In the controller, You could add RoutePrefix to the controller and then specify each additional route directly on the method. Then all methods routes inside the controller will start with api/webhooks/incoming
. To call GetStarted()
the routes will be api/webhooks/incoming/custom
[RoutePrefix("api/webhooks/incoming")]
public class StartUpController : ApiController
{
[HttpGet]
[Route("custom")]
[AllowAnonymous]
public IHttpActionResult GetStarted()
{
return Ok();
}
}
Or you could specify the complete route directly on the method. The route will also be api/webhooks/incoming/custom
public class StartUpController : ApiController
{
[HttpGet]
[Route("api/webhooks/incoming/custom")]
[AllowAnonymous]
public IHttpActionResult GetStarted()
{
return Ok();
}
}
You can read more about it here
Upvotes: 2