Is there any way to achieve multiple responses from a single request using Spring Boot ? If yes, please provide me a link.
1 Answer
HTTP does not work this way. An HTTP request has exactly one response. Spring Boot will not let you send more than one response, because that would be against the HTTP specification and no HTTP clients would be able to figure out what was going on.
There may be another way to accomplish your underlying goals, but whatever it is, it won't involve sending more than one HTTP response to a single HTTP request.
6 Comments
praneeth
Hi Utkarsh, I accept that there will be only one response for request. My approch is I will send a request to some X service which will internally call other service Y, then is there way to send both the responses from X and Y services back to UI ?
Utkarsh
Is this Y service of yours asynchronous ? If not, then you can very well call the service Y, get the response and then return the response back to Service X; where you can do further manipulation on the result returned by Service Y. BTW, what kind of Service are we talking about here ? What kind of response do we get (JSON or HTML ) ?
praneeth
HI Utkarsh, everything mentioned above will work fine. We already had this kind of implementation. But the issue is we need to return the response of Y to front end instead of passing the response to service X. This is where we have an issue. Could you please guide the possible solution and our response is JSON ?
Utkarsh
You need to provide your current implementation(sample code which you tried), that way only anyone here on Stack Overflow(SO) can help you. Your question is very subjective and its not very clear what you are trying to say.
Utkarsh
@MartinAndersson Please feel free to write your own answer.
|