Working with API with different pagination formats
In this document we will learn how we can import a webservice that has pagination different from the one supported in Spring framework.
Introduction
If a webservice has request/response parameters as below, then the widgets (like datatable, list etc.,) will be able to detect pagination and the server side pagination will work out of the box for the widgets. The below response is a spring's Page object.
Request:
GET /api?page=2&size=20
Response:
But, if the request/response parameters differs from above pattern, then the server side pagination will not work. We will have to invoke the API inside a javaservice and explicitly return a Page object conforming to the pattern that is recognised by WaveMaker.
Steps to Create the JavaService
In this example, we will assume an API accepting limit (instead of size) and page parameters, ex: GET /employee?page=1&limit=2
, and the response in below format.
Create a javaservice and specify a name to the service (let's say employeeService)
Create the required model classes involved in request/response of the web service. In this example, we will create a class for Employee and for the actual webservice response. Place the files in the package "com.\<projectname>.\<servicename>.model".
}
- Create a method in the javaservice with a pageable argument (pageable represents the page,size and sort query parameters). Invoke the webservice using RestTemplate, and pass the acutal pagination parameters accepted by the API. The response is then wrapped in a Page object and returned from the method.
@ExposeToClient public class MyJavaService {
}