Configure Proxy to send success response to client and make Asynchronous calls to multiple target servers using JS callout

Not applicable

Hi, I have an usecase to build API proxy which should respond to client with success code and also make asynchronous call to the target server. The target server would take sometime to respond. Once the response is received, I need to make another call based on the response to other target server.

Idea is not to keep the client waiting, success response to the client and do the process asynchronously.

I am using Javascript callout and httpclient to call the target server without waitForComplete. Problem is I am not able to read the response and perform the logic without waitForComplete.

Any advise or sample please?

0 6 672
6 REPLIES 6

Have you any experience with Node JS?

By creating an Express JS app and uploading it to Apigee as a script target, you have better control of this type of behaviour. You are able to call res.send() to send a response back to the client and then perform additional processing afterwards (the second call to your target)

I believe this would work, however it would be good to understand your use case. Often things like error handling can be challenging using the approach you are using. Would it make more sense for the client to make a fire and forget request to your API instead? That way the API itself isn't hiding errors for all clients.

Example scenario: the first target call fails every time for some reason. How will you debug this? Will it involve the client contacting you personally to obtain logs?

Hi Sean, Thanks for the reply. Yes, client would fire the request and forget. The process involves manual intervention, so client would request the status in a different call. I will try express.js.

But, if this is to be implemented in js callout, how can I read the response without using waitForComplete? Trying to understand if this is feasible with js callout.

You cannot - you need to wait for the request to complete before reading the response 🙂

Ok, thanks for the reply Sean...

akoo
New Member

Hi @Kavitha Chittibabu,

Based on your question and comments to Sean's response, it sounds like the current solution (using JS async HTTP client and waitForComplete) and perhaps Node.js may not meet your requirements. Have you considered implementing a WebHook implementation to let your client (server) know when the processing has completed? Or perhaps the backend server can carry out the subsequent additional requests.

Just some ideas, although it's hard to provide more solutions without knowing the full extent of your requirements and setup.