Is it possible to mock a paginated API response?
# help
p
Is it possible to mock a paginated API response?
m
you could match a specific query parameter
Copy code
"request": {
    "urlPath": "/api/users",
    "method": "GET",
    "queryParameters": {
      "page": {
        "matches": "1"
      }
    }
  }
👍 1
l
You could certainly add the matchers for the query parameters. To get the actual correct paginated response from one of your mocks you can keep it simple by mocking a response where there is only one page of results. This allows you to use standard wiremock features. If you want something more dynamic, you are probably going to need to investigate the state plugin so allow you to store the items the mock is returning along with the correct counts for the number of items being returned etc . https://github.com/wiremock/wiremock-state-extension
p
There are APIs that returns next page token, based on which you make next api call to get the next page. I think for that we might need to use state extension as you mentioned. Thanks @Lee Turner.
👍 1
t
It depends what you want to paginate. If you can generate the data either randomly or derive it from the page number you could do it entirely with response templating