specify resource query parameters or post body

Not applicable

When I define an API proxy from Edge UI, I can create resources with supported methods. But for GET method I don't know how to specify the accepted query parameters and for POST, I don't know how to specify JSON body format. How do i do that from Edge UI?

1 3 610
3 REPLIES 3

Not applicable

Typically you would do this with an ExtractVariables policy. Something like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="extractUserInfo">
    <DisplayName>extractUserInfo</DisplayName>
    <FaultRules/>
    <Properties/>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="allowpersonalisation">
            <JSONPath>$.allowpersonalisation</JSONPath>
        </Variable>
        <Variable name="user-id">
            <JSONPath>$.user-id</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">response.content</Source>
</ExtractVariables>

Then in a subsequent step raise a fault if these variables are not present.

<Step>
	<Name>raiseFaultSKUNotFound</Name>
	<Condition>(merchant.sku = "" or merchant.sku = NULL)</Condition>
</Step>

This pattern can be applied to query params, payload elements, etc. Required parameters, payload elements, headers, etc can be enforced this way. If your interest is more around documenting the supported parameters then you would use something like Swagger outside of Edge to accomplish this.

Great question!!

I don't think you can specify that when you configure a resource. However when you publish the documentation for your API with Swagger or WADL, developer portal (with SmartDocs) lets you show a sample JSON request with default parameters to your POST method. In case of a GET request, you can specify the default header & Query param values as well. This will help your Developers know about the input params & get acquainted with the API before they actually start using it. This is in addition to all the detailed documentation you publish for your APIs.

If your question is more around validating those inputs, then @David Allen's answer would help you.

+1 Sudhee and Allen,

If you chose to implement your proxies in nodejs using apigee-127[https://github.com/apigee-127/a127-documentation/wiki],

You could define params, payload formats in a swagger format - define what is required and what are optional etc.. a127 can automatically do lot of these validations for you. You could run the api you built with a127 on apigee itself

Thanks,