-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Support various ways to encode collections in URL parameters for declarative HTTP interfaces #33154
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
Comments
BTW, I created a PR that simply adds the |
The example is with HTTP GET parameters in the query, but On the server side we apply the |
@rstoyanchev Thanks for the explanation 🙂
It is not intended to extend to form data. It's a bit embarrassing, but I just realized that we can bind form data with a combination of This issue and the PR I created were initially thought of from a client side perspective only. We often concatenated collection type parameters into strings with a pre-request delimiter to meet certain API specifications, which I thought was uncool, and Spring Cloud OpenFeign is proposing to migrate to the Spring Framework's declarative HTTP interface as feature-complete. So my personal opinion is that it wouldn't be a bad idea to look at it from a client-side perspective, i.e. to support this feature only on HTTP interfaces using HTTP clients, including |
Also, First of all, I identified that it would be nice to have such a feature as an issue and PR which is not perfect, but it can be implemented without much modification. If you have any ideas for a different, more generalized approach to implementing this feature (which you've outlined), and if it's possible, I'd be happy to work on it 🙂 |
HTTP POST of form data with I propose that we start by making |
I analyzed the code according to your guide and understood the logic behind the integration of I have a few questions before I start working on it.
@HttpExchange(contentType = "application/json")
private interface TestApiClient {
@HttpExchange(contentType = "application/x-www-form-urlencoded;charset=UTF-8")
@PostExchange(contentType = "application/json")
void test();
}
|
@doljae I am suggesting that we start with the |
@rstoyanchev @Configuration
class RestClientConfiguration {
@Bean
fun testApiClient(conversionService: ConversionService): TestApiClient {
val restClient =
RestClient.builder()
.baseUrl("http://127.0.0.1:8080")
.build()
val adapter = RestClientAdapter.create(restClient)
val factory = HttpServiceProxyFactory.builderFor(adapter)
.customArgumentResolver(RequestParamArgumentResolver(conversionService, true)) // new boolean field, formatAsSingleValue
.build()
return factory.createClient(TestApiClient::class.java)
}
} |
I make draft PR. Please check I'm working in the right direction 🙂 |
I'll close this as superseded by #33220. Let's continue there. |
Uh oh!
There was an error while loading. Please reload this page.
I've been making good use of the declarative HTTP interface feature that was added in the latest spring release.
I would like HTTP interface to be a bit more versatile and support different encoding methods for
@RequestParam
.Currently, the encoding method for
@RequestParam
of type collection seems to be repeating the same key with &, which seems to be related to the wayRequestParamArgumentResolver
is implemented.Of course Modern web frameworks expect
@RequestParam
to be deserialized to collection type automatically, either by repeating the same key value as &, or by parsing strings joined by certain delimiters.However, if this is not possible due to limitations of older web frameworks or API specs, we have to join the strings with a specific delimiter before the request and then pass the strings as
@RequestParam
, which is not cool.It would be nice to have the ability to encode
@RequestParam
via @CollectionFormat, which is supported by Spring Cloud OpenFeign. I think users who use declarative HTTP interface will have experience with Spring Cloud OpenFeign and will expect a smooth transition.I'm curious to know what the maintainers think about this 🙂
The text was updated successfully, but these errors were encountered: