Pagination / Sort support in http interface client
It would be great if http interface clients had support for:
- Page as a response type
- Pageable / Sort as request parameters
interface FooClient {
@GetExchange("/foos")
public fun getFoos(
pageRequest: Pageable,
): Page<Foo>
}
This would bring feature parity for what is supported in controllers today. I believe spring openfeign clients support this as well
Original: https://github.com/spring-projects/spring-framework/issues/32286
We have Pageable parameters on Spring Cloud OpenFeign client methods. The lack of Pageable support blocks us from switching to HTTP interface clients. I'm experimenting with this work around. Define a custom argument resolver:
public class PageableArgumentResolver implements HttpServiceArgumentResolver {
@Override
public boolean resolve(Object argument, MethodParameter parameter, HttpRequestValues.Builder requestValues) {
if (!parameter.getParameterType().equals(Pageable.class)) {
return false;
}
if (argument != null) {
var pageable = (Pageable) argument;
if (pageable.isPaged()) {
requestValues.addRequestParameter("page", String.valueOf(pageable.getPageNumber()));
requestValues.addRequestParameter("size", String.valueOf(pageable.getPageSize()));
}
Sort sort = pageable.getSort();
if (sort.isSorted()) {
for (Sort.Order order : sort) {
requestValues.addRequestParameter("sort", order.getProperty() + "," + order.getDirection().name());
}
}
}
return true;
}
}
Invoke the HttpServiceProxyFactory.Builder customArgumentResolver method to register the custom argument resolver.
We started implementing an HTTP client using an HTTP interface client as well and just stumbled upon this issue after researching how to implement pagination.
I guess the answer is: We can't. Unfortunate 😄
So +1 for this issue.
Hey @mp911de,
I'm facing the same issue described in this ticket. Do you plan to implement this feature? Or it is other project's scope e.g.: spring boot autoconfiguration?
Thanks,
For the time being, it's in our backlog as we hadn't had any chance to come up with a design with our limited bandwidth.