I have the following endpoint available to users:
http://blabla-test.apigee.net/mocker/sessions/{sessionId}:{action}
Where `sessionId` is an number and `action` corresponds to an event (start or stop in our case). A real example:
http://blabla-test.apigee.net/mocker/sessions/87189917820:start
http://blabla-test.apigee.net/mocker/sessions/87189917820:stop
It is possible for a user to extend or start and session based on the `action` sent. Different `actions` will provide different mocked responses, which we are serving through AssignMessage policies (JSON payloads).
I have tried the ExtractVariable policy to pull `sessionId` and `action` from the URIPath. However, I'm unsure how to use those variables in a condition flow, from what it looks like I can only use the variables in a JS callout.
Flow variables can be used in a conditional flow like this:
https://docs.apigee.com/api-platform/reference/conditions-reference
And in policies which support variable inputs, such as AssignMessage: https://docs.apigee.com/api-platform/reference/policies/assign-message-policy#top_of_page
So you could, for example have a step like this:
<Step> <Condition>extracted.action = "start"</Condition> <Name>AM-Mock-Start</Name> </Step>
With a policy like this:
<AssignMessage continueOnError="false" enabled="true]" name="AM-Mock-Start" > <AssignTo createNew="false" transport="http" type="response">response</AssignTo> <DisplayName>AM-Mock-Start</DisplayName> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> <Set> <Payload contentType="text/plain"> Session ID {extracted.session} successfully started </Payload> <StatusCode>200</StatusCode> </Set> </AssignMessage>
And this would use the session ID and action extracted from the request to set the response to the success message only when the extracted.action variable is set to "start".
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |