The following defines the different policies that can be used when creating an API.
rateLimit
reqMapping
rateLimit
)This policy allows for rate limiting calls based on the leaky bucket algorithm.
api
, tenant
, resource
.true
, false
.true
, the rate limit applies to each user with a vaild subscription.false
, the rate limit applies the collective usage from all users.Example:
{ "type": "rateLimit", "value": { "interval": 60, "rate": 120, "scope": "api" "subscription": "true" } }
The example above will rate limit an API for each subscription at 120 requests per 60 seconds, or 2 req/sec.
reqMapping
)This policy allows you to map incoming request values to various locations in the actual backend request. It generally adheres to the following template:
{ "type": "reqMapping", "value": [ { "action": "<action>", "from": { "name": "name1", "location": "<gatewayLocation>" }, "to": { "name": "name2", "location": "<backendLocation>" }, }, ... ] }
insert
, transform
, remove
, default
body
, header
, query
, path
If you want to perform multiple request mappings, you can add multiple objects into the value
array. Note that depending on the type of action you want to perform, the structure of these objects will change slightly, as described in detail below.
Insert a new value in to the backend request.
Example:
{ "action": "insert", "from": { "value": "application/json" }, "to": { "name": "Content-type", "location": "header" } }
This will insert the value of application/json
into a header
named Content-type
on the backend request. Note that the format of the from
block is different from the template above.
Move a value from the apigateway request to the backend request.
Example:
{ "action":"transform", "from":{ "name":"foo", "location":"query" }, "to":{ "name":"bar", "location":"body" } }
This will move the value of the foo
query parameter from the incoming request to the bar
field in the backend request body.
You can also specify *
as the name
for the mapping to apply for all fields in that location.
Example:
{ "action": "transform", "from": { "name": "*", "location": "query" }, "to": { "name": "*", "location": "body" } }
This will move all incoming query
parameters into the body
in the backend request.
To define a path parameter, you will need to wrap curly brackets {}
around the path parameter in the url.
Example:
Mapping an incoming path parameter to a backend path parameter
/api/<tenantId>/test/{foo}/hello
https://openwhisk.ng.bluemix.net/api/v1/namespaces/APIC-Whisk_test/actions/{MYACTION}
"policies": [{ "type": "reqMapping", "value": [{ "action": "transform", "from": { "name": "foo", "location": "path" }, "to": { "name": "MYACTION", "location": "path" } }] }]
Remove a field from the request.
Example:
{ "action": "remove", "from": { "name": "foo" "location": "body" } }
This will remove the foo
field from the body of the incoming request, so that it's not passed to the backend request.
Insert a default value, if it's not supplied in the incoming request.
Example:
{ "action": "default", "from": { "value": "bar" }, "to": { "name": "foo", "location": "header" } }
This will assign bar
to a header
called foo
, but only if the value is not already set. Note that this policy is only supported for body
, header
, query
locations.