Client-Side Usage Examples
You can specify how many results you want for each page and optionally the page of results with which to start, by using one of the following methods defined in the JadeRestRequest class.
-
setPaginationLimitOnly method, which sets the limit of how many results to display for each page, starting at the first page of results as defined by the server.
-
setPaginationOffsetAndLimit method, which sets the limit of how many results to display for each page, starting at the index specified in the offset parameter.
Use this method when the REST API method returns an Array or Set.
-
setPaginationKeyAndLimit method, which sets the limit of how many results to display for each page, starting at the first object that has the key specified in the keyName parameter equal to the value specified in the keyValue parameter.
Use this method when the data to be paginated is in an Array.
The following is an example of a client‑side REST service request for results from the server‑side REST service.
getCustomers(); vars client : JadeRestClient; request : JadeRestRequest; response : JadeRestResponse; begin client := create JadeRestClient("http://localhost/JadeRestSite/jadehttp.dll/"); request := create JadeRestRequest("customers"); /* Use this to get a page of 10 results, starting at the beginning of the collection. It can be used where the getCustomers REST API method returns a Dictionary, Array, or Set. */ request.setPaginationLimitOnly(10); /* Use this to get a page of 10 results, starting with the customer with the name Wilbur, where the getCustomers REST API method returns a Dictionary. */ request.setPaginationKeyAndLimit("name", "Wilbur", 10); /* Use this to get a page of 10 results, starting with the 30th customer in the Array, where the getCustomers REST API method returns an Array. */ request.setPaginationOffsetAndLimit(30, 10); create response transient; client.get(request, response); write response.data; while response.hasMorePages do response.getNextPage(); write response.data; endwhile; end;
When you have got the paginated results back from the server, you can use the JadeRestResponse class getNextPage method to get the next page of results. If the server is using:
-
Link header pagination, you need only call the getNextPage method as shown in the previous example. The JadeRestResponse object will be repopulated with the next page of results.
-
Envelope‑based pagination, you will need to first use the JadeRestResponse class parsePaginationEnvelope method. This method will establish the link to the next page of results, enabling the getNextPage method to produce and return an envelope object that you can use to get the data.
The parsePaginationEnvelope method takes two parameters: an envelope class (for example, JadePaginationEnvelope) and an ObjectArray. If you are consuming a Jade REST API, you can use JadePaginationEnvelope, but if you are consuming a third‑party REST API, you will need to define the envelope class according to the server’s documentation. This class must implement the JadePaginationEnvelopeIF interface, which has one method: getNextPage. Implement this method to get the URL to the next page of results according to the format of the envelope that the server uses. For example, consider a third‑party REST API that returns an envelope with the following format.
{ "data":[{obj1}, {obj2}, {obj3} ...], "pagination": { "nextPage": "<link-to-next-page-of-results>", "firstPage": "<link-to-first-page-of-results>", "prevPage": "<link-to-previous-page-of-results>", "lastPage": "<link-to-last-page-of-results>" } }
You would need to define two classes, as follows.
The following image is an example of the required second class.
You could then pass the ThirdPartyEnvelopeExample class as defined above to the parsePaginationEnvelope method to enable the getNextPage method.
2022.0.01 and higher.