'REST API Single Request - Multiple responses

I am writing a REST API in JAX-RS 2.0, JDK 8 for the below requirement

POST API /server/fileUpload/ (Multipart Form data) where I need to send a Big .AI (Adobe Illustrator) File in this.

The Server, takes the file and return Status 202 (Accepted), Acknowledging that file transfer happened Successfully. (From endpoint to Server)

Now at the Server, I am using Java + Imagemagik to convert .AI File (20-25 MB File) to small JPG Thumbnail, place on a Apache HTTP Server and share the location (like http://happyplace/thumbnail0987.jpg)

Now the Second Response should come from Server with Status 200 OK and Thumbnail URL

is it feasible with one REST API? (Async/similar)

or should I split it to 2 API calls, Please suggest



Solution 1:[1]

No. In http, one request gets one response. The client must send a second request to get a second response.

Solution 2:[2]

You can use WebSockets for that.

Solution 3:[3]

If you are calling from script the call will be async you can handle the Thumbnail URL when you get a response. When you are calling from java program i suggest to run it on a different thread, If the execution is not sequential i.e ( Remaining lines can be executed without getting URL). If url is needed for the remaining section of code you can make one call and wait for the response then execute remaining code.

Solution 4:[4]

You need to make different APIs for both scenarios. One for showing file upload status and another for all file conversion and manipulation.

On the client side second request must be callback of first request.

Solution 5:[5]

The best way to handle these kind of scenario is to use Java Reactive (Project Reactor, WebFlux).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DwB
Solution 2 Eduardo A EDUARDO Fernandez Di
Solution 3 Karthik Tsaliki
Solution 4 Anmol Middha
Solution 5 Naveen Jain