Is there a way to pass request information to a second proxy for logging purposes?

Hello,

I have created a series of Proxies to service my organization's APIs. We are looking to capture the request information sent to one API (for example, apikey, time the request took, and other relevant statistics and information) and send that to a second Proxy which serves a different API that we will use to store that information.

For example a user makes an API call with query parameters of start_date=10/1/2018, end_date=10/7/2018. They also submit their apikey (via a header variable that we already capture). And the request completed and returned their data in 2500ms.

Is there a way to have that information sent to a second Proxy automatically, after the requester's data has been returned?

Thank you

1 3 503
3 REPLIES 3

There are ways to connect one proxy to another.

  1. proxies themselves "listen" on a virtual host. There's an HTTP endpoint. One proxy can invoke the other proxy's http endpoint, using one of: ServiceCallout, JavaScript httpClient, or Target server.
  2. Proxy chaining allows calls from one proxy to another without using the HTTP stack. Basically it's a local call. This can be done via ServiceCallout and Target server , with a LocalTargetConnection.

Separately, There is a way to "require" logic to run within the API Proxy at specific stages during an API Proxy lifecycle. The mechanism is called "Flow Hook". One of those stages is at the end.

Combining these, you could configure a ServiceCallout (with a local target connection) to call your second proxy. Then place that ServiceCallout into a ... a Flow hook. And the result is that every API Proxy would call this service callout at the end of its run.

All this stuff is documented on https://docs.apigee.com .

Thank you for the help.

Do you know how I could take the request sent to the first proxy and pass that information to the second proxy, that will be called by the Flow Hook/ServiceCallout combination?

I'm currently trying to create variables to store that information, but I seem to be losing those variables after the response from the first API.

Yes - "the request" I guess entails everything about the request? that would mean

  • virtual host and host alias
  • method (GET, POST, PUT, etc)
  • url path
  • headers
  • query params
  • payload (form params or json or whatever)
  • TLS session?

All of those things ARE available in context variables, and those variables are constant across the target request and response. Most of them have a prefix of "request." So, for example, "request.header.content-type" is the variable name that contains the header "content-type". "request.content" is the payload. "request.verb" has the verb , or method. And so on. All documented here.

Rather than going through each of those variables for the different pieces, you can sort of "clone" the request message if you like using the AssignMessage policy. My good friend Anil has put together a quick 4minute video describing how to do this. In fact the scenario in that video seems to be exactly what you 're trying to do.

good luck!