Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What are the options in a web api to indicate that the returned data is paged and there is further data available. ASP.Net Web API with OData uses a syntax similar to the following:

{
    "odata.metadata":"http://myapi.com/api/$metadata#MyResource","value":[
    {
        "ID":1,"Name":"foo"
    },
    ...
    {
        "ID":100,"Name":"bar"
    }
   ],"odata.nextLink":"http://myapi.com/api/MyResource?$skip=20"
}

Are there any other ways to indicate the link to the next/previous 'page' of data without using a metadata wrapper around the results. Can this be achieved by using custom response headers instead?

share|improve this question

1 Answer

Let's take a step back and think about WebAPI. WebAPI in essence is a raw data delivery mechanism. It's great for making an API and it elevates separation of concerns to a pretty good height (specifically eliminating UI concerns).

Using Web API, however, doesn't really change core of the issue you are facing. You're asking "how do I want to query my data store in an performant manner and return the data to the client efficiently?" Your decisions here really parallel the same question when building a more traditional web app.

As you noted, oData is one method to return this information. The benefit here is it's well known and well defined. The body of questions/blogs/articles on the topic is growing rapidly. The wrapper doesn't add any meaningful overhead.

Yet, oData is by no means the only way you can do this. We've had to cope with this since software has been displaying search results. It's tough to give you specific advice without really understanding your scenario. Here are some questions that bubbled up as I read your question :

  • Are your results sets huge but users only see the first one or two pages?
  • Or do user tend to page through all of the results?
  • Are pages of results limited (like 20 or 50 per page) or 100's/ 1000's ?
  • Does the data set shift rapidly, so records are added as the user is paging?
  • Are your result sets short and adding columns that repeat tolerable?
  • Do you have enough control over the client do do something out of band -- like custom HTTP headers, or a separate HTTP request that just asks for a query summary?

There really are hundreds of options depending on your needs. I don't know what you're using as a data store, but I wrote a post on getting row count efficiently. The issues there are very germane here, albeit from the DB perspective. It might help you get some perspective.

share|improve this answer
 
Thanks for those comments. As a bit of background I am using Azure Table storage as my data store and API requests could potentially return large data sets with the associated overhead. This is why I am considering paging. I don't really have a problem with the implementation of retrieving the data, and I'm not discounting using OData but I was wondering whether there were any other options. –  Jonny S Aug 16 at 15:09
 
Still too general, at least for my brain:-) Just return the data in a shape that works for you. If that's oData - great. If it's a List<T> and T has a field that includes "CurrentRow" and "TotalRows", that works too. If it's a custom nested object serialized to JSON, great. If you want out of band with HTTP headers, that can work too. Heck, you could accomplish this through a cookie. There are as many combinations as you have time to invent. –  EBarr Aug 16 at 15:47
 
Also, my point about the SQL stuff was not that you might have query issues. Instead I meant that thinking about how to shape the data is really very similar at the DB level and this level. Search results have two components meta data (total rows, current row/page) and then the actual data. So how do you shape that? Two queries? One query? Nested object? What's the expense? etc... –  EBarr Aug 16 at 15:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.