APIM260 - F3.1 - API - Gateway

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

WSO2 API Manager 2.6.

0
Fundamentals
API Gateway
WSO2 Training

1
API Gateway

What is an API
Gateway?

The API Gateway is a runtime, backend component (an API proxy) developed using
WSO2 ESB. The API Gateway secures, protects, manages, and scales API calls. It
intercepts API requests, applies policies such as throttling and security using handlers
and manages API statistics. Upon validation of a policy, the Gateway passes Web
service calls to the actual backend. If the service call is a token request, the Gateway
passes it directly to the Key Manager.

When the API Manager is running, you can access the Gateway using the URL
https://localhost:9443/carbon. You integrate a monitoring and statistics component to
the API Manager without any additional configuration effort. This monitoring
component integrates with WSO2 Data Analytics Server, which can be deployed
separately to analyze events. For more information, see Working with Statistics.

Although the API Gateway contains ESB features, it is recommended not to use it for
ESB-specific tasks. Use it only for Gateway functionality related to API invocations.
For example, if you want to call external services like SAP, use a separate ESB cluster
for that.
API Gateway Processing Flow

API Gateway
Access Apply QoS Custom
Validate Token Publish Statistics
Token Policy Extensions

Is Token Valid? Yes/No

Validate Token

When a request comes to the API Gateway, it extracts the access token and validates
it against the key management server and then applies the QoS policy and then the
custom extensions that are defined are applied. If BAM/DAS is configured, statistics
will be published.
User Roles of API Gateway

API Invoker
Caching

API Store API Gateway


Cache Cache

Response Resource
Cache Cache

Key Manager
Cache

Link - Configure Caching

When an API call hits the API Gateway, the Gateway carries out security checks to
verify if the token is valid. During these verifications, the API Gateway extracts
parameters such as access token, API and API version that are passed on to it. Since
the entire load of traffic to APIs goes through the API Gateway, this verification
process needs to be fast and efficient in order to prevent overhead and delays. The
API Manager uses caching for this purpose, where the validation information is
cached with the token, API name and version, and the cache is stored in either the
API Gateway or the key manager server.

Different types of caching


- API Gateway cache (caching keys at the gateway)
- Resource cache (caching http calls)
- Key Manager cache (caching keys at the key manager)
- Response cache (caching backend responses)
- API Store cache (caching store content like last 5 APIs)
Validation Information Caching

Caching the Key Manager

Invoke APIM Gateway Validate APIM Key Manager

Cache

1. Populate cache entry for token


2. Key validation happens

Link - API Gateway Caching


3. Validation information gets added to cache entry
4. JWT token also cached
5. Resources level details are cached
6. Call goes to key manager only if there is no cached entry

Validation information caching API Gateway level

When caching is enabled at the Gateway and a request hits the Gateway, it first
populates the cache entry for a given token. If a cache entry does not exist in cache, it
calls the key manager server. This process is carried out using Web service calls.
Once the key manager server returns the validation information, it gets stored in the
Gateway. Because the API Gateway issues a Web service call to the key manager
server only if it does not have a cache entry, this method reduces the number of Web
service calls to the key manager server. Therefore, it is faster than the alternative
method.
Validation Information Caching

Caching the Key Manager

Invoke APIM Gateway Validate APIM Key Manager

Cache

1. All invocation calls arrive to the key manager


2. If no cached entry token validated against DB
3. Disable JWT caching if a JWT token is needed for
Link - API Gateway Caching each call

Validation information caching API Gateway level

When caching is enabled at the Gateway and a request hits the Gateway, it first
populates the cache entry for a given token. If a cache entry does not exist in cache, it
calls the key manager server. This process is carried out using Web service calls.
Once the key manager server returns the validation information, it gets stored in the
Gateway. Because the API Gateway issues a Web service call to the key manager
server only if it does not have a cache entry, this method reduces the number of Web
service calls to the key manager server. Therefore, it is faster than the alternative
method.
Response Caching

The API Manager uses WSO2 ESB's cache mediator to cache response messages per
each API. Caching improves performance, because the backend server does not have
to process the same data for a request multiple times. To offset the risk of stale data
in the cache, you set an appropriate timeout period.

You can enable response caching when creating a new API or editing an existing one
using the API Publisher UI. Go to the API Publisher and click the Add API menu (to
create a new API) or the Edit link associated with an existing API. Then, navigate to
the Manage tab where you find the response caching section. You can set it to
Enabled and give a timeout value. This enables the default response caching settings.
THANK YOU

wso2.com

You might also like