Skip to content
Branch: master
Find file History
Type Name Latest commit message Commit time
Failed to load latest commit information.
apiproxy Update pagination sample Jun 15, 2017
restaurant_locator_target/apiproxy Update pagination sample Jun 15, 2017 Update pagination sample Jun 15, 2017 Update pagination sample Jun 15, 2017
paginationCache.xml Adding a sample that paginates a cached response using XSLT. Apr 8, 2014

Pagination and caching sample

Sample use case

Paginate a cached response using XSLT.

Note that if you create the proxies by manually deploying the and files in your organization, you'll need to manually create an environment cache called paginationCache, as described in the Apigee documentation.


This sample uses these policies:

  • alt text XSL Transform: To apply an XSLT stylesheet to the response body. The stylesheet extracts specified elements and applies offset and limit parameters.
  • alt text Extract Variables: To extract query parameters from the request.
  • alt text Response Cache: To cache the response from the backend service.
  • alt text Assign Message: To set the paginated payload in the response.


This sample involves 2 API proxies: restaurant_locator and pagination.

restaurant_locator serves as a local target (using API proxy chaining) that returns a list of restaurants in XML.

The pagination proxy calls restaurant_locator, caches the response, and uses XSLT to return only a subset of restaurants. The list of restaurants that are returned is controlled by two query parameters you'll provide in the request: limit and offset.

  • limit - Defines how many results to return. For example, 2 means return only 2 restaurants.
  • offset - Defines the starting point for returned results. For example, an offset of 3 indicates that the results should begin with the 3rd restaurant in the list.

While you can use the script to make the call, here's a sample cURL request:

curl -v http://{org}-{env}"offset=1&limit=2"

Use of the Response Cache policy illustrates a common pattern in API proxy design for improving API performance.

Some benefits of this technique include:

  • You don't need to do pagination of the results in the app running on a mobile device.
  • You don't need to implement pagination in your backend service.
  • Response caching improves performance.

XSLT Stylesheet

This is the XSL stylesheet used in this example:

<xsl:stylesheet xmlns:xsl="" version="1.0">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" />
        <xsl:param name="offset" select="offset"/>
        <xsl:param name="limit" select="limit"/>
        <xsl:template match="/">
                <xsl:for-each select="/RestaurantLocator/Restaurant">
                 <xsl:if test="position() &lt; number($limit+$offset) and position() &gt; number($offset)-1">
                     <xsl:copy-of select="."/>

Set up, deploy, invoke

See the main project README file for information about setting up, deploying, and invoking sample proxies.


This screen shot from the Apigee Edge trace tool shows the placement of the policies used in this sample.

alt text

More information

Policy used in this sample

Ask the community

alt text

Copyright © 2017 Google

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.