java – How to break up a request into multiple requests


I have a question about following scenario I am trying to implement in Java JAX-RS REST:

  1. a client app sends request to my api, lets call it MY-API
  2. MY-API receives request, and sends it to vendor api (VENDOR-API)
  3. VENDOR-API replies back to MY-API
  4. MY-API replies back to the client

My questions is about point 2 and 3 above.

  • Is it possible to break up request coming from client app once it is
    received in MY-API so that MY-API sends multiple requests to
    VENDOR-API instead of one?
  • And then upon receiving the requests from VENDOR-API, combine them
    back into single response to client app?

I am thinking about something like this in pseudo code:

@Path("cars")
public class CarsController
{
     1. send request to /car-detail endpoint
     1.a. get response from /userDetails endpoint

     2. send request to /car-image endpoint
     2.a. get response from /userImages endpoint
     
     3. send request to /car-history endpoint
     3.a. get response from /userHistory endpoint

     5. Somehow build response for /cars from the
        3 requests above and send response back to client
}