Getting Started - shephertz/App42-API-Gateway-Sample GitHub Wiki
Getting Started with API Gateway
Basic Concepts
API gateway is simplified solution for developing, managing and deploying APIs for your enterprise. API Gateway allows you to create an API on the fly with services wrapped around like Authentication, Authorization, Security, Analytics, Provisioning, Orchestration, Mediation, Auditing and other management features.
1. Creating An API
One can create an API either through proxy to already existing API or you can create your your through writing server side code using JAVA language. If you already have an API and want to wrap with standard gateway services offering, you can directly go to step 3. If you wan to create an API from scratch, proceed to next step.
2. Creating your own API
You can create your own API by writing a server side logic. To create your own API, just download API Sample eclipse sample project and import this in to your eclipse. You will find a sample java file in side it named as com.test.MyAPI. This class implements Executor interface and you can write your logic inside execute method as shown below. Also, you are free to rename this class file based on your requirement.
Create API
![CreateAPI] (https://github.com/shephertz/App42-API-Gateway/blob/APIGateway_Snapshots/createAPI.jpg)
public class MyAPI implements Executor {
@Override
public HttpResponseObject execute(HttpRequestObject requestObject) {
//Get Request Body
String requestBody = requestObject.getBody();
//Get Header Map
HashMap<String, String> requestHeaders = requestObject.getHeaderMap();
// ########### Write your Logic Below ############//
//................................................//
//................................................//
//................................................//
// ########### Logic End ############//
// Send Your Response.....
HashMap<String, String> responseHeader = new HashMap<String, String>();
responseHeader.put("MyCustomHeader", "XXXXXXX");
int responseStatus = 200; // OK...
String responseMessage = "{'message':'Success/Custom Message'}"; // You can pass your custom message
return new HttpResponseObject(responseStatus, responseMessage , responseHeader);
}
}
Once you have written your logic, you can create jar of this project and deploy it on gateway. You can create jar file using any java jar utility or running maven command (ant jar) from root of this project folder. You can deply this created jar from logging to Gateway console as shown below.
3. Deploying API
You can deploy a new API through configuration wizard as shown below in screen shot. Here are the list of parameters and respective explanation of each.
Name : Name of the API that you want to deploy.
Version : Version of API.
Allowed Method : Allowed Method that can be accessed from client.
Proxy Host : Host name where API is running (For Proxy API only).
Proxy Port : Port number where API is running (For Proxy API only).
Proxy URI : URI for API (For Proxy API only).
Jar File : Jar file path (For your created API).
Entry Class Name : Name of class which implements Executor interface.
Authentication : True/False
Burst Limit : Request Burt Limit per Second.
Max Request Size : Maximum allowed request Size.
Signature Validation : True/False (Applicable if Authentication is enabled ).
Timestamp Validation : True/False (Applicable if Authentication is enabled ).
Timestamp Validity : True/False (Applicable if Authentication is enabled ).
Allowed Request Time : Maximum allowed request time.
Allowed Content Type : Allowed Content Type (Application/JSON, application/XML etc.).
White List IP : IPs which are allowed to access to API. Specify 0.0.0.0 to white list all.
Black List IP : IPs which are not allowed to access to API. Only applicable if White List value is 0.0.0.0
Allowed Domain : Allowed domain to access this API. (xyz.com, specify ALL to allow it for all host)
Deploy Existing API(Proxy)
![Proxy To Existing API] (https://github.com/shephertz/App42-API-Gateway/blob/APIGateway_Snapshots/deployApp-proxy.jpg)
Deploy New API JAR File
![New API JAR Deploy] (https://github.com/shephertz/App42-API-Gateway/blob/APIGateway_Snapshots/deployApp-jar.jpg)
4. IAM and Authorizing API
If you have enabled authentication for your API, you have to create an IAM (Identity Access Management) key to access that API. An API key can have as many IAM key as possible. One IAM key is logically a subscriber of your API which will be uniquely identified through IAM key.
An IAM key can use its own configuration setting of an API. For example, an IAM key can have its own burst limit set to 50 however other IAM keys may use global setting of burst limit (say 40). Any settings given in IAM will override global setting of API. Below are the list of settings that can be overridden.
Burst Limit : Request Burt Limit per Second.
Max Request Size : Maximum allowed request Size.
Signature Validation : True/False (Applicable if Authentication is enabled ).
Timestamp Validation : True/False (Applicable if Authentication is enabled ).
Timestamp Validity : True/False (Applicable if Authentication is enabled ).
Allowed Request Time : Maximum allowed request time.
Allowed Content Type : Allowed Content Type (Application/JSON, application/XML etc.).
White List IP : IPs which are allowed to access to API. Specify 0.0.0.0 to white list all.
Black List IP : IPs which are not allowed to access to API. Only applicable if White List value is 0.0.0.0
Allowed Domain : Allowed domain to access this API. (xyz.com, specify ALL to allow it for all host)
Create IAM
![Create IAM] (https://github.com/shephertz/App42-API-Gateway/blob/APIGateway_Snapshots/CreateIAM.png)
IAM Listing
5. Using and Testing API
After you have deployed your API, it would be exposed through REST interface and you can test/run it using any REST client. You can also test it through Gateway console as shown below.
6. Analytics and Metering
API gateway does metering and Analytics when APIs are called, you can do real time reporting and analysis by logging in to console as shown below.
API Call Distribution Graph
![API Call Distribution Graph] (https://github.com/shephertz/App42-API-Gateway/blob/APIGateway_Snapshots/APICountGraph.png)
API Avg. Request Time Graph
![Avg. Request Time ] (https://github.com/shephertz/App42-API-Gateway/blob/APIGateway_Snapshots/RequestTimeGraph.png)