Create An API Gateway
Â
Intro
An Azure API gateway is an instance of the Azure API management service.
Documentation
Â
Tips and Tidbits
The name you use for the gateway must be globally unique within the .azure-api.net namespace.
Â
Â
Steps
Â
Â
Deploy a Web App
The app includes Swashbuckle to generate OpenAPI Swagger documentation.
 let's start by running a script to host our RESTful API in Azure. The script performs the following steps:
Source code: https://github.com/MicrosoftDocs/mslearn-publish-manage-apis-with-azure-api-management
Create an Azure App Service plan in the free tier
Create a Web API within an Azure App Service, configured for Git deployment from a local repo
Set account-level deployment credentials for our app
Configure Git locally
Deploy our Web API to our App Service instance
Â
git clone https://github.com/MicrosoftDocs/mslearn-publish-manage-apis-with-azure-api-management.git
Â
*********************** IMPORTANT INFO *********************
Swagger URL: https://ShoeCoAPI970b9d9a89.azurewebsites.net/swagger
Swagger JSON URL: https://ShoeCoAPI970b9d9a89.azurewebsites.net/swagger/v1/swagger.json
Â
Â
Deploy an API gateway
Â
Import and publish an API
To make an API available through an API gateway, you need to import and publish the API.
Making an API available starts with importing the API into API Management. You can then:
Use the visualization tools in the API gateway to test out your API.
Manage access to your APIs using policies.
There are various API frameworks and standards. API Management provides you with several options for importing APIs.
Type | Details |
---|---|
Blank API | You can import an API with a blank API definition. You then manually specify all the required parameters. |
Open API | Open API is a specification that documents all the endpoints and operations for RESTful APIs, and all input and output parameters. OpenAPI was originally called Swagger. |
WADL | Web Application Description Language is an XML description of HTTP-based web services. It is a simpler format and more lightweight than WSDL. |
WSDL | Web Service Description Language is an XML description of any network service, not just HTTP. |
Logic App | Logic apps are used to orchestrate and automate workflows and integrations with various data sources. |
API App | An API hosted within an API app service in Azure. |
Function App | Serverless code that can be called through triggers. |
Exercise - Import and publish an API
Â
OpenAPI specification | Paste the swagger JSON URL that you saved from the previous exercise. |
https://shoecoapi970b9d9a89.azurewebsites.net/swagger/v1/swagger.json
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "NorthWindShoes Products"
},
"host": "shoecoapi970b9d9a89.azurewebsites.net",
"paths": {
"/api/Inventory": {
"get": {
"tags": [
"Inventory"
],
"summary": "Retrieve the entire product inventory for the company.",
"operationId": "GetInventory",
"consumes": [],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Success",
"schema": {
"uniqueItems": false,
"type": "array",
"items": {
"$ref": "#/definitions/Inventory"
}
}
}
}
}
},
"/api/Inventory/{productid}": {
"get": {
"tags": [
"Inventory"
],
"summary": "Retrieve the number in stock for the specified product",
"operationId": "GetInventoryItem",
"consumes": [],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"parameters": [
{
"name": "productid",
"in": "path",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/Inventory"
}
}
}
}
},
"/api/Products": {
"get": {
"tags": [
"Products"
],
"summary": "Retrieve the details of every product sold",
"operationId": "GetProducts",
"consumes": [],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Success",
"schema": {
"uniqueItems": false,
"type": "array",
"items": {
"$ref": "#/definitions/Product"
}
}
}
}
}
},
"/api/Products/{productid}": {
"get": {
"tags": [
"Products"
],
"summary": "Find the details of the specified product",
"operationId": "GetProductDetails",
"consumes": [],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"parameters": [
{
"name": "productid",
"in": "path",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/Product"
}
}
}
}
}
},
"definitions": {
"Inventory": {
"type": "object",
"properties": {
"productID": {
"format": "int32",
"type": "integer"
},
"numberInStock": {
"format": "int32",
"type": "integer"
}
}
},
"Product": {
"type": "object",
"properties": {
"productID": {
"format": "int32",
"type": "integer"
},
"productName": {
"type": "string"
},
"productLaunchDate": {
"format": "date-time",
"type": "string"
},
"productLaunchPrice": {
"format": "int32",
"type": "integer"
}
}
}
}
}
Â
Visualize the API
Â
Â
Â
Â
Subscription Keys
Â
When you publish an API, you often want some level of control over who can access the API through the gateway. Subscription keys are used to restrict access to an API.
Â
A subscription key is a unique auto-generated string which needs to be passed through in the headers of the client request.
The key is directly related to a subscription which can be scoped to different areas, this gives granular control over permissions and policies.
The three main subscription scopes are:
All APIs
A Single API
A product
Â
Â
With the key in the header
Â
Deploy the Weather Web API
Â
Â
 all dependencies needed for our app to run are automatically installed on the remote App Service.
Â
Â
Â
Â
Â