API Creation
App42 API Gateway enables you to expose your backend systems in the form of REST APIs that can then be consumed by any device over HTTP/HTTPS. APIs you create:
- 1. Act as a front door for the applications to access your backend systems
- 2. Allow you to use analytics, monetization, authentication, throttling, quota and rate limit, and many other features of App42 API Gateway
App42 API Gateway provides you the facility to expose your backend systems in many ways. It can simply be a Proxy Passthrough where you already have a REST enabled backend and want to expose it through App42 API Gateway, or it can be through your Web Services as REST APIs. You can even expose APIs without any backend system involved by writing just your business logic in Java and uploading it in Gateway to expose as REST APIs. They are explained below in detail:
Proxy API
You should create Proxy Passthrough type of API when you already have your backend running over REST and you want to add other functionalities to your APIs like Authentication and Authorization, Rate and Quota limit, Caching, Pre-processing and Post-processing.
Steps to create Proxy API:
- 1.Navigate to APIs > Manage. Click on Create API
- 2.Select API Type as Proxy and click on Create
- 3.Select Project for which you want to create API. Provide mandatory details like API name, Content Type for your proxy API (Enable CORS if you want Cross-Origin Resource Sharing) and click on Add Operation
- 4.Provide the Operation name, HTTP method, Target Endpoint, Proxy Path and then click on Submit
- 5.You can see your created Operation with all the details
- 6.Once Operation is added, you can perform various actions on it like Edit, Add Headers, Add Query Params and you can also Delete the Operation
- 7.To add a header in the API click on Add Header. By default header is mandatory, the corresponding exception code and message will be thrown if this header is not passed in the request. Fill in the details and click on submit
- 8.Similarly you can Add Query Params as well
- 9.Once you have added the Operations for your API click on Create
- 10. You can see that your API gets created for the selected Project
JAR API
It allows you to expose REST APIs with no backend system involved. These are serverless APIs. You simply need to write your business logic in Java and upload it in App42 API Gateway which will then be exposed as an API.
Steps to create JAR API:
- 1.Navigate to APIs > Manage. Click on Create API
- 2.Select API Type as JAR and click on Create
- 3.Now Select Project for which you want to create JAR API. Provide mandatory details like API name, Content Type and upload your Java API JAR file (Enable CORS if you want Cross-Origin Resource Sharing). Please refer this link for steps to write your Java API JAR file
- 4.Click on Add operation
- 5.Provide Operation Name, Select HTTP Method and provide the Entry class for your JAR API. Click on Submit
- 6.Once Operation is added, you can perform various actions on it like Edit, Add Headers, Add Query Params, and you can also delete the Operation
- 7.To add a header in the API click on Add Header. By default header is mandatory, the corresponding exception code and message will be thrown if this header is not passed in the request. Fill in the details and click on submit
- 8.Similarly you can Add Query Params as well
- 9.Once you have added the Operations for your API click on Create
- 10. You can see that your JAR API gets created for the selected Project
SOAP API
If you have SOA-based web services and want to expose them as REST APIs with other functionalities, you should create SOAP type of API.
Steps to create SOAP API (RESTful API Proxy):
- 1.Navigate to APIs > Manage. Click on Create API
- 2.Select API Type as SOAP and click on Create
- 3.Select Project for which you want to create API. Provide mandatory details like API name, Content Type and WSDL Endpoint for your SOAP API (Enable CORS if you want Cross-Origin Resource Sharing). Click on Validate to validate the WSDL
- 4.Once you click on Validate and if your WSDL is validated successfully, you will see the various Port Types & Operations that are present in your WSDL file
- 5.Select the port type and the operations which you want to include in your API
- 6. Select the HTTP Method (you can also add Headers and Query Params)
- 7.Click on Create and your SOAP API will get created
Writing JAR 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.
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); } }