dimanche 23 janvier 2022

Chaining of rest API calls [closed]

Problem : orchestration design pattern or implementation

use case : I have n rest api calls each has it's own request and response and they should be called in sequence like response of 1 can be used in making request of another call and in end i need to return final response which can have values mix of all responses from diff api's.

Prototype or Pseudocode as below : 

Class - > returnType methodName(RequestObject request)

Service A - > ResponseObjectA callA(RequestObjectA request)
Service B - > ResponseObjectB callB(RequestObjectB request)
Service C - > ResponseObjectC callC(RequestObjectC request)
Service D - > ResponseObjectD callD(RequestObjectD request)


public class OrchestrationService {


@Autowired
ServiceA a;

@Autowired
ServiceB b;

@Autowired
ServiceC c;

@Autowired
ServiceD d;

 public finalResponse orchestrationFlow(OrchestrationRequest request) {

--transformer to convert request to RequestObjectA
ResponseObjectA roa = a.callA(RequestObjectA)
--transformer to convert request and roa to RequestObjectB
b.callB()
-- tranformer
c.callC()
--transformer
d.callD()

--Made finalResponse

}

This is how i am doing right now, but it seems to be tightly coupled. Can anyone suggest me how i can achieve this in a loosely coupled way ? I looked for chain of responsibility design pattern but not able to think from design point of view.

Aucun commentaire:

Enregistrer un commentaire