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.

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:

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.