-
Notifications
You must be signed in to change notification settings - Fork 38.5k
RestClient - Add support for asynchronous calls #34290
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
Hello @ThomasVitale , thanks for reaching out. I have discussed this issue with @sdeleuze and he shared some additional context for this issue. This calls for a broader response so I'll start with that. We have designed HTTP client libraries do support asynchronous calls, but in different ways. For example, the JDK's
We will reconsider this in the future but in the meantime I will close this issue as we have nothing actionable on this right now. |
As I've been struggling with this issue in the SpringAI and MCP projects, I can second @ThomasVitale's suggestion. RestClient's lack of async support makes it incompatible with Server-Sent Events (SSE), which is crucial as virtually all GenAI APIs use SSE for streaming responses. While I've implemented a custom HttpClient-based solution (FlowSseClient) for MCP, this workaround isn't suitable for Spring AI's broader needs. Using WebClient with its heavy, coupled client/server dependencies and auto-configurations is an unfortunate design choice that significantly impacts the Spring AI architecture and user experience. |
Thanks for the feedback @tzolov . Spring Framework structured this in order to avoid tangles and split packages and for many other reasons. I agree that the effect on auto-configurations is not ideal. The Spring Boot team is considering splitting auto-configurations and creating dedicated starters for clients. |
@bclozel Thanks for your answer. |
The
RestClient
provides a very convenient API on top of HTTP Clients implementations from OpenJDK, Apache, Jetty, and Netty. All those HTTP Clients provide support for performing asynchronous calls. However, theRestClient
APIs do not support asynchronous behavior.The current alternative is skipping Spring and using the underlying HTTP Client library directly or switching to reactive.
I would like to suggest extending the
RestClient
to support asynchronous calls, and I'm available to help out anyway I can.The text was updated successfully, but these errors were encountered: