Kode
Kode

Reputation: 3215

Azure Mobile Web Services REST Results Per Page for Pagination

I am using Azure Mobile Web Services for my backend data exposed via REST/JSON. I have not been able to locate documentation that states how many results are posted per page, and how to page through them, as I need to incorporate server side paging for my Angular app.

GITs API has something as follows:

Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the ?page parameter. For some resources, you can also set a custom page size up to 100 with the ?per_page parameter.

Is there anything similar in Azure's Mobile Web Service API/Does anyone know the results per page and how to page thru them? Ex. https://myrestcall.net/tables/articles?page=2

Upvotes: 1

Views: 177

Answers (1)

javiborr
javiborr

Reputation: 36

If you are using the Javascript client you can check out this page

How to: Return data in pages

By default, Mobile Services only returns 50 rows in a given request, unless the client explicitly asks for more data in the response. The following code shows how to implement paging in returned data by using the take and skip clauses in the query. The following query, when executed, returns the top three items in the table.

var query = todoItemTable.take(3).read().done(function (results) {
   alert(JSON.stringify(results));
}, function (err) {
   alert("Error: " + err);
});

Notice that the take(3) method was translated into the query option $top=3 in the query URI.

The following revised query skips the first three results and returns the next three after that. This is effectively the second "page" of data, where the page size is three items.

var query = todoItemTable.skip(3).take(3).read().done(function (results) {
   alert(JSON.stringify(results));
}, function (err) {
   alert("Error: " + err);
});

Again, you can view the URI of the request sent to the mobile service. Notice that the skip(3) method was translated into the query option $skip=3 in the query URI.

Upvotes: 2

Related Questions