I have a controller marked with [Route("api/entities")]
. There is a method for getting all entities:
[Audit(ActionType.EntityList)] // custom annotation for audit
[Authorize]
[HttpGet]
public IActionResult GetEntities()
{
// ...
}
As you can see, by using annotations I save the request to some audit and authorize the request only to allowed users.
Now, I want to enhance this endpoint so it can return the top N entities. Example request: /api/entities?top=5
. I have found that I should use an optional parameter for the method and use if
to detect the case.
However, I need to save such call in audit as differnt type (e.g. [Audit(ActionType.EntityTop)]
) and I do not need an authorization there (everyone can fetch the top entities).
How can I map the /api/entities
request to one method and /api/entities?top=N
to another? In Spring from Java I would use a params
field of @RequestMapping
.
I do not want to change the URL of this endpoint, because the top
parameter modifies only the list that is being returned so one should use GET parameters for that. By having the same URL I also do not change the semantic meaning of the response (it is still list of the same entities). It is important when using RESTful frontend framework like Restangular.