I have a .NET Core controller action method in FileController
like this:
[HttpGet("{filename}")]
public async Task<IActionResult> Get([FromRoute] string filename, int take, int skip = 0)
{
// process file
}
So it gets the filename from the route.
Is there any way to get the values of take
and skip
also from the route?
Instead of adding them to the body of the request.
So a request would look like:
https://localhost:43845/File/myfilename.txt/10/1
So take would be 10 and skip would be 1
I wouldn't do that - the URL describes the resource - but the Take
and Skip
are not part of the resource, they're just "additional" information (sometimes called "metadata") - so they really shouldn't be part of the URL either.
I would pass them in as query parameters like this:
/file/myfilename.txt?take=10&skip=2
Additionally - Take
and Skip
are typically only applied to collections of resources, so to a call to /files
- not to a single resource like just that one file in your request.