A microservices application is comprised of a number of services. The most common type of service is the Web API. In this article, we will install and explore the operations two Web APIs.
The API Services requires the following:
- Azure SQL Database
- Azure Service Bus
Azure SQL Database
Install an Azure SQL Database in your azure account or use an existing database and copy the following parameters for use later on :
- SQL Server name
- SQL Server database name
- SQL Server login username
- SQL Server login password
For detailed instructions on creating an Azure SQL Database, refer to the Azure SQL Server Documentation
The API Services communicate with each other via an Azure Service Bus. We created a Service Bus in the previous section for the API Services. Copy the following parameters from the Service Bus to configure the API Services later on in this article.
- Service Bus Name (in this instance, rclmsg)
- Primary Key for the Service Bus
The product service is an ASP.NET Core Web API. It manages products for a store.
To install Product Service in your cluster run the following commands.
Update the helm repository
helm repo update
Install Product Service, replace the [placeholder] text with your data.
helm install rcl-apps/productsvc-sample --set dbServerName=[db-server-name] --set dbName=[db-name] --set dbUserName=[db-user-name] --set dbPassword=[db-password] --set sbName=[service-bus-name] --set sbKey=[service-bus-key] --set host=[dns-name]
The host parameter is the DNS name for your cluster. You can find it by clicking on the Public IP for the cluster in the resource group.
Once the Product Service is installed , navigate to the API documentation at:
If you try to access the API, you should get an ‘Unauthorized’ error. The reason for this is that the API is secured by Identity Service and requires and access token to make a request.
Obtaining an Access Token for the API
In this section, we will use Identity Service to issue Access Tokens to allow us to make authorized requests to the API.
Navigate to the Identity Service and create a new API in the Admin section. Name the api ‘productapi’.
Add a scope to the API. Call this scope ‘productapi-full’. The api scope allows a client to access the API.
The Product Service must now be configured as a client to access the API. Create a new client, and name the client ‘productsvc-sample’.
Add a client secret with the value ‘1234’. After you create the secret is will be hashed.
Finally, add the ‘productapi-full’ scope to the list of allowed Client Scopes for the client to access the API.
In the Product Service, click on the ‘Authorize’ button and enter the client id and client secret and select the api scope to authorize the request.
You should now be able to access the API.
The Order Service manages orders for the store. To install the Order Service in your cluster, run the following commands. replace the [placeholder] text with your data.
helm install rcl-apps/ordersvc-sample --set dbServerName=[db-server-name] --set dbName=[db-name] --set dbUserName=[db-username] --set dbPassword=[db-password] --set sbName=[service-bus-name] --set sbKey=[service-bus-key] --set host=[dns-name]
Once the Order Service is installed , open the API Documents by navigating to : https://[your-dns-name]/ordersvc/api-docs
In the following steps , we will configure Identity Service to make authorized requests to the API. In the Identity Service Admin portal, create a new API and name it ‘orderapi’.
Add a scope to the ‘orderapi’ in order for a client to access the API. Name this scope ‘orderapi-full’.
Create a client to access the API. Name the client ‘ordersvc-sample’.
Add a client secret value of ‘1234’.
Finally, add the API scope, ‘orderapi-full’, to the allowed Client Scopes to allow the client to access the API.
In the Order Service, click on the ‘Authorize’ button , and add the client id, client secret and select the API scope to make authorized requests to the API.
The next article in this website will walk you through installing a frontend website in your AKS cluster.
Next Article : Frontend Website