api gateway setup

19
{ API GATEWAY SETUP INTRODUCTION The API Gateway runtime points to the backend APIs and services that you define and abstracts them into a layer that the Anypoint Platform manages. Consumer applications invoke your services. APIs route to the endpoints that the gateway exposes to enforce runtime policies and collect and track analytics data. The API Gateway acts as a dedicated orchestration layer for all your backend APIs to separate orchestration from implementation concerns. The gateway leverages the governance capabilities of the API Manager, so that you can apply throttling, security, and other policies to your APIs.

Upload: sivachandra-mandalapu

Post on 12-Jan-2017

67 views

Category:

Education


0 download

TRANSCRIPT

Page 1: API gateway setup

{

API GATEWAY SETUPINTRODUCTIONThe API Gateway runtime points to the backend APIs and services that you define and abstracts them into a layer that the Anypoint Platform manages. Consumer applications invoke your services. APIs route to the endpoints that the gateway exposes to enforce runtime policies and collect and track analytics data. The API Gateway acts as a dedicated orchestration layer for all your backend APIs to separate orchestration from implementation concerns. The gateway leverages the governance capabilities of the API Manager, so that you can apply throttling, security, and other policies to your APIs.

Page 2: API gateway setup
Page 3: API gateway setup

Pre requisites AnypointStudio 3.6.0+ Jdk 1.7 APIKit Cloudhub account

Page 4: API gateway setup

Process Here, I am going to create a POC

(Addition of 2 numbers) in Mule (3.6), deploy the application in Cloud and apply proxy for the same.

Step 1 POC (Addition of 2 numbers): Flow:

Page 5: API gateway setup
Page 6: API gateway setup
Page 7: API gateway setup
Page 8: API gateway setup

HTTP:

Page 9: API gateway setup

SetPayload:

Page 10: API gateway setup

.mflow

<?xml version="1.0" encoding="UTF-8"?><mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsdhttp://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd" version="EE-3.5.2"> <apikit:config name="api-config" raml="api.raml" consoleEnabled="true" consolePath="console" doc:name="Router"/> <apikit:mapping-exception-strategy name="api-apiKitGlobalExceptionMapping" doc:name="Mapping Exception Strategy"> <apikit:mapping statusCode="404"> <apikit:exception value="org.mule.module.apikit.exception.NotFoundException" /> <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> <set-payload value="{ &quot;message&quot;: &quot;Resource not found&quot; }" doc:name="Set Payload"/> </apikit:mapping> <apikit:mapping statusCode="405"> <apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException" /> <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> <set-payload value="{ &quot;message&quot;: &quot;Method not allowed&quot; }" doc:name="Set Payload"/> </apikit:mapping> <apikit:mapping statusCode="415"> <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" /> <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Set Payload"/> </apikit:mapping> <apikit:mapping statusCode="406"> <apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException" /> <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> <set-payload value="{ &quot;message&quot;: &quot;Not acceptable&quot; }" doc:name="Set Payload"/> </apikit:mapping> <apikit:mapping statusCode="400"> <apikit:exception value="org.mule.module.apikit.exception.BadRequestException" /> <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/> <set-payload value="{ &quot;message&quot;: &quot;Bad request&quot; }" doc:name="Set Payload"/> </apikit:mapping> </apikit:mapping-exception-strategy> <flow name="api-main" doc:name="api-main"> <http:inbound-endpoint doc:name="HTTP" exchange-pattern="request-response" host="localhost" path="add" port="8081"/> <apikit:router config-ref="api-config" doc:name="APIkit Router"/> <exception-strategy ref="api-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/> </flow> <flow name="get:/Addition/{num1}/{num2}:api-config" doc:name="get:/Addition/{num1}/{num2}:api-config"> <set-payload value="#[Integer.parseInt(flowVars['num1'])+Integer.parseInt(flowVars['num2'])]" doc:name="Set Payload"/> </flow></mule>

Page 11: API gateway setup

api.raml:

#%RAML 0.8---title: Addition of two numbersbaseUri: http://addition-api/apiversion: 1.0 /Addition/{num1}/{num2}: displayName: Provide input Details here get: description: Enter input details responses: 200: body: application/json:

Page 12: API gateway setup

Step 2 Deploy and test the above POC in cloud: Login to the anypoint.mulesoft.com (cloudhub).

https://anypoint.mulesoft.com/login/#/signin

Go to Runtime Manager tab and deploy the above POC.

Click Deploy application tab, upload the zip file (POC) and deploy the application.

Provide application name, zip file, runtime version and deploy the application.

Page 13: API gateway setup

Test the application: Service URL: -> Get the service URL from the logs of

above deployed application. Open the above URL in browser and

provide the input details accordingly.

Page 14: API gateway setup
Page 15: API gateway setup
Page 16: API gateway setup

Step 3 How to apply proxy for the

above deployed application: Go to API Manager. Click Add new API tab. Provide the new API details. Provide the above created RAML file and

update the baseURL (get it from Step 2: C.1).

Create new portal. Configure endpoint details. Request API access to get the new

clientID and client secret details. Apply clientID policy. Deploy the proxy.

Page 17: API gateway setup

Get the proxy URL from the logs of above deployed application.

Test the deployed application.

Page 18: API gateway setup
Page 19: API gateway setup

References https://docs.mulesoft.com/api-manager/c

onfiguring-an-api-gateway