Search code examples
javascriptrestpostgetrpc

Trace Chain of API Calls


Let's say I have an API (A) that then makes calls to other APIs (B, C, D), is there a way for me to return all the REST/RPC calls that are made even when they are from the API that I called?

So I am looking for a way to make a call to A and then get a result that says something like "Calls made: You -> A, A -> B, A -> C, A -> D". If it can do an even deeper dive that would be great!

I see that there is https://www.charlesproxy.com/ but I am not sure if this is what I am looking for since it appears it is just returning the shallow list.


Solution

  • The General Answer

    In general, you can't.

    Why: If an API you call (A), calls another API (B), there is no way to know that, unless that API (A) explicitly provides that information somehow. There is no way to do some "traceroute" on API calls, arbitrarily, because each one controls what they return, and "what other APIs they called" is not standard information required or expected from any API.

    Possible Solution

    If you control all those APIs, then you can make (or follow) a protocol that has all involved API implementations provide their "trace" of contained API calls in a response envelope or response headers.