Unit 04.4 - A Closer Look at The API Owner - Policy Designer
Unit 04.4 - A Closer Look at The API Owner - Policy Designer
PUBLIC
Objectives
Route
Proxy End Point Rules # Target End Point
Client Backend
Condition Condition
Post Flow Pre Flow Post Flow Pre Flow
Flows * Flows *
Although not 1:1 compatible, documentation at Apigee is quite good & comprehensive with lots of
examples, http://docs.apigee.com/api-services/reference/reference-overview-policy
Often there are context variables / „flow variables“ available that you can use; see
http://docs.apigee.com/api-services/reference/variables-reference or search on apigee.com (Code
completion in Editor is missleading!)
➢ Do not use special characters when working with Policies (neither in the name nor elsewere).
➢ Don‘t use spaces in the name. You might need to reference them later
➢ Be careful when working with the XML coding-snippets. Currently even the order of tags can be the
cause of an error.
• request.queryparam.apikey
• request.header.ApiKey
context.setVariable("response.content", newpath);
Identifier ref="verifyapikey.CheckAPIKey.client_id“
See http://docs.apigee.com/api-services/reference/quota-policy
https://help.hana.ondemand.com/apim_od/frameset.htm?1f742c1e1a5c4a21bd839940
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 22
71ddaea0.html
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Public 22
Maintain Quotas in API Product Access Control
Previous Policy-Step:
ContinueOnError = true
Condition String:
ratelimit.SetQuota.failed = "true"
Policy Name
RaiseFault Policy:
set FaultResponse
See http://docs.apigee.com/api-services/reference/raise-fault-policy
MessageWeight:
To distinguish between heavy and
simple calls
Per-minute rates get smoothed into full requests allowed in intervals of seconds.
For example, 30pm gets smoothed like this:
Flow Variable: 60 seconds (1 minute) / 30pm = 2-second intervals, or 1 request allowed every 2
ratelimit.<PolicyName>.failed = seconds. A second request inside of 2 seconds will fail. Also, a 31st request within a
minute will fail.
"true" Per-second rates get smoothed into full requests allowed in intervals of milliseconds.
For example, 10ps gets smoothed like this:
Rate: 1000 milliseconds (1 second) / 10ps = 100-millisecond intervals, or 1 request allowed
every 100 milliseconds. A second request inside of 100ms will fail. Also, an 11th request
Calls per Second (ps), Minute (pm) within a second will fail.
See http://docs.apigee.com/api-services/reference/spike-arrest-policy
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 29
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Public 29
Unit 4.4.4c - Policy Designer – Spike Arrest
AllowConnection: Specifies the number of connections to the backend service. TTL determins the number of
seconds after which the counter is automatically decremented (in case there was not proper decrement via the
response path)
Not fully configurable in the UI as the policy also needs to be placed in the Fault Rules
HTTP status 500 (Internal Server Error) 500 (Internal Server Error) 503 (Service Unavailable)
code when Your org can optionally be configured to return an HTTP Your org can optionally be configured to return an HTTP status
limit has been status code of 429 (Too Many Requests) instead. * code of 429 (Too Many Requests) instead. *
reached:
Good to •Quota counter is stored in Cassandra. •Performs throttling based on the time at which the last traffic •Keeps a count of concurrent connections per message
know: •Configure the policy to synchronize the counter was received. This time is stored per message processor. processor.
asynchronously to save resources. •If you specify a rate limit of 100 calls per second, only 1 call •While an individual API proxy may be handling just a
•Asynchronous counter synchronization may cause a delay every 1/100 second (10 ms) will be allowed on the message few connections, collectively, the connections to a set of
in the rate limiting response, which may allow calls slightly processor. A second call within 10 ms will be rejected. replicated API proxies pointing to the same backend
in excess of the limit you've set. •Even with a high rate limit per second, nearly simultaneous service may swamp the capacity of the service. Use this
requests may result in rejections. policy to limit this traffic to a manageable number of
connections.
Get more Quota policy Spike Arrest policy Concurrent Rate Limit policy
details:
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 33
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Public 33
Backend Authentication
Assign Message
Basic Authentication
Basic Authentication
Assign Message
Allows to set variables, like a
username and password
See http://docs.apigee.com/api-services/reference/assign-message-
policy
Basic Authentication
Retrieves and encodes information (like
username and password) and sets
header variables
See http://docs.apigee.com/api-services/reference/basic-
authentication-policy
See http://docs.apigee.com/api-services/reference/response-cache-policy
See: http://docs.apigee.com/api-services/reference/response-cache-policy
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 40
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Public 40
Unit 4.4.7 - Policy Designer - Caching
https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 43
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Public 43
CORS Example
Access-Control-Allow-Origin = *
See
https://help.hana.ondemand.com/apim_od/frameset.htm?4dfd54a754
6c42cfb8dd157ab1355011.html
See
https://help.hana.ondemand.com/apim_od/frameset.htm?4dfd54a754
6c42cfb8dd157ab1355011.html
„request.verb == „OPTIONS“
➢ Access-Control-Allow-Origin
➢ Access-Control-Allow-Credentials
➢ Access-Control-Expose-Headers
➢ Access-Control-Allow-Methods
➢ Access-Control-Allow-Headers
Basic Authentication is the simplest way to authenticate a user in a standard way. The user
will be prompted to provide username and password, which will then be sent as HTTP
Authorization header (base64 encoded).
1. Server to send challenge for User Name and password with HTTP 401 response
including header: WWW-Authenticate: Basic realm=“<Name>“
In API Management Key Value Maps can be used to avoid hard-coding specific values
within the API Proxy.
Header:
• Key Value Map API is part of API Portal csrf-token: <token value>
Authorization: Basic dXNlcjpwYXNz
• It is OData compliant
Body:
{
• Url is: "name":"KM1",
https://<apiportalhost>/apiportal/api/1.0/Manageme "keyMapEntryValues":[
{
nt.svc/KeyMapEntries
"name":"username",
"value":"user",
• Requires CSRF Token: "map_name":"KM1"
• Authenticated Call using HEAD Verb and Header x- },
{
csrf-token: fetch
"name":"password",
• Subsequent call using supplied csrf token (and all "value":"pwd",
supplied cookies) "map_name":"KM1"
}
]
}
© 2017 SAP SE or an SAP affiliate company. All rights reserved. ǀ PUBLIC 56
© 2016 SAP SE or an SAP affiliate company. All rights reserved. Public 56
Key Value Map Policy Key Value Map