Store response in Apigee Edge

crich
New Member

In Apigee Edge proxy is it possible to store a response body against a unique key?

For a login flow, for a successful request, my login API returns a user record POST /login

In the POST request, I pass an authCode e.g

{
   "authCode": "abcdef"
}

Login returns this payload:

{
   "name": "John",
   "customerId": "12345"
}

I now want Apigee to store the payload against the authToken and set an expiry.
So on subsequent API requests I want Apigee to do a token exchange by accepting "abcdef" and returning the user record.

How would I set this up?

PS I have very little experience with Apigee Edge.

0 1 140
1 REPLY 1

You can use ResponseCache policy - https://docs.apigee.com/api-platform/reference/policies/response-cache-policy

For cache key you can use authCode. Extract authCode from request using Extract variable policy as shown below & add Response cache policy after Extract variable.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV.ExtractVar">
    <DisplayName>EV.MakeUnregisteredCreditCardPaymentResponse</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="authCode">
            <JSONPath>$.authCode</JSONPath>
        </Variable>        
    <Source clearPayload="false">request</Source>
</ExtractVariables>

Sample ResponseCache policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ResponseCache async="false" continueOnError="false" enabled="true" name="RC-RespnseCache">
    <DisplayName>RC-RespnseCache</DisplayName>
    <Properties/>
    <CacheKey>        
        <KeyFragment ref="authCode" type="string"/>
    </CacheKey>
    <Scope>Exclusive</Scope>
    <ExpirySettings>        
        <TimeoutInSec ref="">600</TimeoutInSec>
    </ExpirySettings>   
</ResponseCache>

Note - make sue that only successful login is cashed. When you add Response cache policy, it will be attached in preflow and target post flow. Make sure that you add appropriate condition in target postflow.