Search code examples
paginationrestsharp

how to implement paging with RestSharp


I am using RestSharp to consume a REST style service. Pretty new to this library and would appreciate some guidance on how to implement paging using RestSharp.

Any existing examples on how to achieve this?

RestSharp - http://restsharp.org/

Thanks


Solution

  • There's no concept of paging inherent to RestSharp. It's just a thin wrapper over HTTP calls, so it's what the HTTP endpoint you're calling that determines what features are available, like how paging is handled.

    Here's an example of an API that supports paging, and how you would call it with RestSharp:

    public CallResult ListCalls(CallListRequest options, int pageNumber, int count)
    {
        var request = new RestRequest();
        request.Resource = "Accounts/{AccountSid}/Calls.json";
    
        request.AddParameter("From", options.From);
        request.AddParameter("To", options.To);
        request.AddParameter("Url", options.Url);
    
        // send paging parameters required by API
        request.AddParameter("Page", pageNumber);
        request.AddParameter("PageSize", count);
    
        var client = new RestClient("http://example.com");
        return client.Execute<CallResult>(request);
    }