I know how to add support for Query parameters on a GET request to the endpoint /resources, for example. That would be:
[HttpGet]
public async Task<IHttpActionResult> GetAll([FromUri] QueryData queryData) {
//... Do some stuff
}
In my example, QueryData would be a class containing all my supported query parameters:
public class QueryParam {
public int Page { get; set; }
public int Size { get; set; }
}
So, then I can call the endpoint: /resources?page=2&size=4, and retrieve those parameters successfully.
But, what about doing the same but on the endpoint: /resources/2??
2 is a segment of the URL and it specifies the id of the resource.
At the moment, I am handling the method as follows:
[HttpGet]
public async Task<IHttpActionResult> Get(int id) {
//Do some stuff...
}
This works fine, but then I tried to modify it as:
[HttpGet]
public async Task<IHttpActionResult> Get(int id, [FromUri] QueryData queryData) {
//Do some stuff...
}
I hope it would work as it did on the other method, but it doesn't. Probably, because of the id, which is not retrieved by query parameters, but instead is part of the URL path.
Is it possible to add query parameters to such an URL, and be able to retrieve both the id and those parameters?
I'm looking forward to be able to call the endpoint: /resources/2?lang=en