I'm trying to build a Web API for a complex type of searching. I want to support paging in the results. The "state" of the search is complex, so not really suitable for persisting in the query string. But I'd like for the paging options to be included within the query string.
I've implemented two methods, as below, and the web api code seems to understand what I'm trying to do, but the query string parameters never get assigned. Any hints or advice on this would be appreciated:
public Task<HttpResponseMessage<SearchResults>> Post(SearchRequest request) //Method 1
{
return Post(request, null, null);
}
public async Task<HttpResponseMessage<SearchResults>> Post(SearchRequest request, string page, string pageSize) //Method 2
{
//All of the complex code, including...
if (PageNo < TotalPages)
{
searchResults.AddLink(new Link { Uri = Url.Route("DefaultApi", new {
controller = "AdvancedSearch",
page = (PageNo + 1).ToString(),
pageSize = PageSize.ToString() }),
Relation = "nextPost" });
}
//Final wrap up, etc
}
On POSTing a SearchRequest to /api/AdvancedSearch, Method 1 is called, which in turn calls Method 2, which does the search, and packages up the results. As you can hopefully see, included in this result (if more pages of results are available) is a URL to post to for the next page. The generated URL base on this is /api/AdvancedSearch?page=2&pageSize=20, exactly as I'd hoped.
In my calling code, I then perform a POST to this second URL. Only Method 2 is invoked (as expected). But, both page and pageSize are null.
What am I doing wrong? Or what else do you need to see in order to answer this question?
HttpResponseMessage<T>is being dropped so you might need to redesign yours.