Saqib Ahmed Saqib Ahmed - 11 months ago 155
reST (reStructuredText) Question

Blocking a REST API response until another API is called

I have following scenario:

There are two API calls in an application:

api1
and
api2
.

api1
is invoked multiple times from multiple users. I want to block all the responses of
api1
calls until
api2
is invoked.
api2
will be invoked with a parameter which would suggest to "release" the response of a specific
api1
invocation. So whenever
api2
is invoked, a specific
api1
call will respond which was blocked until now (there can be multiple
api1
releases based on the parameter passed in
api2
call).

I want to implement this in grails. I'm kind of blank how to implement this. Any ideas?

Do share if you know any other language or framework which can be used to implement this.

Answer Source

A solution that came to my mind is using a mutex on the api1 call and releasing it in the api2. You may have to take into account the timeout of the api1.

EDIT

Well, you can have a dictionary/map of mutex's where each call has a respective mutex. When a client calls api1, the server generates a mutex and adds it to the dictionary, also it tries to lock the mutex(which is locked by default). After that on the api2 you only need to provide the id that you used in the dictionary to unlock the mutex.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download