How to use pagination in Spring Boot — OpenFeign
Let assume that you using Open Feign as HTTP Client which this library
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
and you have requirement to get data from other services with pagination,let says that you have target endpoint like this.
@GetMapping("users")
public ResponseEntity<Page<User>> getUser(Pageable pageable) {
return userService.getUserPageable(pageable);}
Feign Part
Lets create simple page custom object to get page data source above.
and also need to create custom config for Feign Interface that you will used.
because this case using pagination you should make bean PageableQueryEncoder like this
and as usual you use SimplePageImpl on Feign like this,
@GetMapping("/api/users")
ResponseMessage<SimplePageImpl<User>> getUsers(
Pageable page
);
but another important thing is you should add bean PageJacksonModule becaouse feign is using jackson.
If it was interesting or helpful to you, please do press the 👏 clap button and help others find this story too.