07 Installing Web API Microservices

Microservices

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.

Prerequisites

The API Services requires the following:

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 :

For detailed instructions on creating an Azure SQL Database, refer to the Azure SQL Server Documentation

Service Bus

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.

placeholder

Product Service

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.

placeholder

API Docs

Once the Product Service is installed , navigate to the API documentation at:

https://[your-dns-name]/productsvc/api-docs/

placeholder

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.

placeholder

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’.

placeholder

Add a scope to the API. Call this scope ‘productapi-full’. The api scope allows a client to access the API.

placeholder

The Product Service must now be configured as a client to access the API. Create a new client, and name the client ‘productsvc-sample’.

placeholder

Add a client secret with the value ‘1234’. After you create the secret is will be hashed.

placeholder

Finally, add the ‘productapi-full’ scope to the list of allowed Client Scopes for the client to access the API.

placeholder

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.

placeholder

You should now be able to access the API.

placeholder

Order Service

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

placeholder

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’.

placeholder

Add a scope to the ‘orderapi’ in order for a client to access the API. Name this scope ‘orderapi-full’.

placeholder

Create a client to access the API. Name the client ‘ordersvc-sample’.

placeholder

Add a client secret value of ‘1234’.

placeholder

Finally, add the API scope, ‘orderapi-full’, to the allowed Client Scopes to allow the client to access the API.

placeholder

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.

placeholder

Next Steps

The next article in this website will walk you through installing a frontend website in your AKS cluster.

Next Article : Frontend Website

Comments