Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination / Sort support in http interface client #3046

Open
hesselapplications opened this issue Feb 16, 2024 · 2 comments
Open

Pagination / Sort support in http interface client #3046

hesselapplications opened this issue Feb 16, 2024 · 2 comments
Labels
type: enhancement A general enhancement

Comments

@hesselapplications
Copy link

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: spring-projects/spring-framework#32286

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 16, 2024
@mp911de mp911de transferred this issue from spring-projects/spring-data-rest Feb 20, 2024
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 20, 2024
@pukkaone
Copy link

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.

@denniseffing
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants