This is part 34 of azure tutorial. In this video, we'll discuss how to add our APIs to
azure API management service. At the moment, I'm in the azure portal and we are looking at
API management service instance - EmployeeApiManagement. We created this
in our previous video. At the moment we are on the "Overview" blade and if we scroll down a bit,
notice here we have this option APIs and when I click on this,
notice in this middle pane under All APIs, at the moment we have just one API - Echo API. This is
a test API provided by Microsoft, so we can see how things are set up. So, let me click on this.
All the operations that are supported by this test API are listed here. Notice, it supports POST,
PUT, DELETE and a couple of GET operations. Now, what we want to do is, add our own API. Remember,
in our previous videos in the series, we created Employee Management API and hosted it in azure app
service. So we want to add that API to this azure API management instance and for that,
click on this button Add API. As you can see, there are several ways to add your APIs to azure
API management service. One of the options is to create a "Blank API". Obviously this is manual,
meaning you have to add all of your operations manually. So, if you have the time and you want to
do things manually then choose this option. On the other hand, if your API has OpenApi specification
document, then choose this option. This is one of the most common options used to add your APIs.
If your API is a SOAP API and if it has got WSDL that is web service description language then
choose this option. If your API is hosted in azure app service, then choose this option.
We haven't discussed logic apps and function apps yet, we'll discuss them in our upcoming videos.
For now, let's add the API manually by choosing this option - Blank API. First, a display name
for our API - Employee Management. Next, we need to provide the URL of our backend API. Remember,
in our previous videos in this series, we hosted our employee management API in azure app service
and it's available at this URL. At the moment, we are looking at the OpenApi specification document
of our employee management API. Now, to get the list of employees we go to /api/employees and
similarly if you want the list of departments /api/departments. So, let's copy the URL of our
API, up until /api and then paste it in the web service URL text box right here, and then we also
need to provide a suffix for our API. Let's call this "myapi" and then click this "Create" button.
There we go, our API employee management is added and notice at the moment, this API does not have
any operations. We need to add all the operations also manually and if you recollect, our employee
management API supports all these operations. Just imagine, the amount of time and effort it takes
to set all these operations up manually. Now, let's just add one of the operations manually,
so we understand the different moving parts. For that, click on this link here, "Add operation".
Provide a display name for the operation. Let's call this "Get all employees". We want to issue
a GET request and the list of all employees are available at this URI "/employees". You can also
provide a description if you want to and then click - "Save". There we go, our GET operation is
added and it is listed under "All Operations" and if you want to test this click on this "Test" tab.
To this end point we don't have to pass any parameters or headers. We also did
not select any products. We will discuss the concept of products in azure api management
in our upcoming videos and if we scroll down a bit further, notice we have the request URL wired up
right here and along with the request, it's also sending the API subscription key. This is required
for this request to be executed successfully. Now, let's click the "Send" button. Notice,
the request completed successfully. We got the response 200 OK and if we scroll a bit further,
we can see the list of all employees in JSON format as expected. Now, let's see what's going
to happen if we try to issue a request to this URL without the API key. So, let me copy this URL
Paste it here and issue the request. Notice, you have a 401 access denied error - Access
denied due to missing subscription key. If you recollect from our previous videos in this series,
azure API management service is made up of three main components - azure portal,
developer portal and the API gateway and remember API gateway sits on top of our back-end APIs. In
this specific example, we have got just one back-end API and that is employee management
API and remember it is the API gateway that is customer facing which obviously accepts API calls
from the internet and routes them to our backend APIs, in this case to our employee management
API and remember it is this API gateway that verifies API keys and we have seen that in action
just now. If we don't pass the API key, we get that 401 access denied error message. In addition
to verifying API keys, API gateway allows us to use several other features like JWT tokens,
certificates and other credentials. Enforces usage quotas and rate limits. Caches backend responses.
Logs call metadata for analytics purposes. In short azure API management service, specifically
the API gateway, lets us transform our backend APIs on the fly without any code modifications.
Now, manually adding all these operations is tedious, time-consuming and error-prone. So,
let's see how to import this employee API and all of its operations automatically. In the
azure portal, click on this button - Add API. Now, we're going to use OpenApi specification document
to import our employee management API and all of its operations automatically. So
when I click this, we have to specify the URL of our OpenApi specification document.
So, at this URL, we have the OpenApi specification document of our employee management API,
basically this is a JSON document that describes our employee management API
and all of its operations. So, let's copy this URL, paste it here, notice based on the
JSON document, we automatically got the display name and name. You can change both of these if
you want to and then provide a URL suffix. Let's actually name it "empapi" and then click "Create"
There we go, our API and all of its operations are automatically added and if you want to test
any of these operations, click on the "Test" tab and let's try this operation - Get department
by id. Obviously, this endpoints needs a parameter. Let's provide a value of 1
and notice, again we have the request URL
and the API subscription key is also being sent along with the request. Let's click "Send"
Request completed. We can see 200 OK and we have the department in JSON format
as expected. That's it in this video. Thank you for listening.