Skip to content

Allow use of form-backing object for client requests #32142

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

Open
aykborstelmann opened this issue Jan 27, 2024 · 5 comments
Open

Allow use of form-backing object for client requests #32142

aykborstelmann opened this issue Jan 27, 2024 · 5 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@aykborstelmann
Copy link

aykborstelmann commented Jan 27, 2024

Affects: 6.+


I really appreciate the HttpServiceProxyFactory, it is a great feature to easily create a client matching a interface.
However, for large APIs, we usually like to encapsulate multiple parameters in convenience classes, which spring web supports with databinding.

public interface EndpointApi {
  @GetExchange("/endpoint")
  EndpointResponse getProcedures(
      EndpointFilterOptions filterOptions,
      EndpointSortOptions sortOptions,
      EndpointPaginationOptions paginationOptions);
}

@ParameterObject
public record GetProceduresFilterOptions(
        @BindParam("customName")
        UUID filterOne,
        String stringFilter,
        Boolean booleanFilter,
        Set<Types> setFilter) {}
}

However, when creating a client for EndpointApi and using it, no HttpServiceArgumentResolver exists per default to handle such parameters.

I would appreciate this feature out of the box, while I am are that, HttpServiceProxyFactory provides a way to register custom argumentResolvers.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 27, 2024
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 1, 2024
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Feb 9, 2024

@aykborstelmann, thanks for the suggestion. Note that there is currently no such mechanism if using RestClient or WebClient directly. In other words, no message converter that would take an object, turn it into form data, e.g. for POST, or query params for GET. It's not an argument against, but just mentioning.

While I understand the benefit, the main challenge is that in the general case an object can be of arbitrary depth and structure, and there will clearly need to be some limits around what is possible. It also increases the possibility of using objects that were not originally built for this, and end up sending information that wasn't meant to be sent. Even in your example record, the last property is a Set which cannot be expressed with data binding property paths since it is not an indexed collection.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Feb 12, 2024
@bclozel bclozel changed the title Support ModelAttributes / Databinding out of the box in HttpServiceProxyFactory Support ModelAttributes / Databinding out of the box in HttpServiceProxyFactory Feb 14, 2024
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Feb 19, 2024
@aykborstelmann
Copy link
Author

@rstoyanchev yes I'm aware of the difficulties involved.
In theory this must be the inverse of the ModelAttributeMethodProcessor.
I can imagine there might be even cases that are not invertible.
Still I am convinced this feature would be great to encapsulate data in APIs.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Feb 22, 2024
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Jul 9, 2024
@rstoyanchev rstoyanchev added this to the 6.x Backlog milestone Jul 9, 2024
@jhoeller jhoeller modified the milestones: 6.x Backlog, General Backlog Oct 1, 2024
@rstoyanchev rstoyanchev modified the milestones: General Backlog, 7.0.x Dec 2, 2024
@rstoyanchev rstoyanchev changed the title Support ModelAttributes / Databinding out of the box in HttpServiceProxyFactory Allow use of form-backing object for client requests Mar 6, 2025
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 6, 2025

I've updated the title as this applies more broadly to client scenarios including RestClient, WebClient, and testing too, see #29728.

@patpatpat123

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants