I believe microservice architecture is not a weird sound with many developers nowadays🤔. And one or many times, when you guys hear about the microservice, you may listen to some components name API Gateway as well, or somebody calls it API Manager😕. And you know, it is actually essential in today's architecture. It is almost the first thing people must consider when they want to build a microservice architecture. Let's figure out how important it is and how it works😉.
What is Microservice architecture?
At first, let's get a concise brief of microservice architectures.
As a quotation from google cloud:
Microservices architecture (often shortened to microservices) refers to an architectural style for developing applications. Microservices allow a large application to be separated into smaller independent parts, with each part having its own realm of responsibility. To serve a single user request, a microservices-based application can call on many internal microservices to compose its response.
If you are still like @.@ 😖, refer to my header picture, which is more than a thousand words 😂.
Now go to API Gateway (API Manager, or whatever!)
A quotation from Redhat:
An API gateway is a way to decouple the client interface from your backend implementation. When a client makes a request, the API gateway breaks it into multiple requests, routes them to the right places, produces a response, and keeps track of everything. An API gateway is one part of an API management system.
And now, turn to my explanation: your UI only needs to know the address of API Gateway when sending the request; API Gateway will route your requests to a suitable service; refer back to my header picture. 😂
Because of that, it helps backend developers relieve them from thinking about dependencies when developing API, helps UI developers no need to identify an address of each API service, and everybody knows where to look for a specific API when needed.
WSO2 API Manager
A definition from WSO2:
WSO2 API Manager is a fully open-source API management platform. It supports API designing, API publishing, lifecycle management, application development, API security, rate limiting, viewing statistics of APIs, and connecting APIs, API Products, and endpoints.
In other words, it is an API Gateway developed by WSO2, which they named API Manager. 😉
Time for practice 🥳
Start up a local WSO2 API Manager.
The simplest way, and the way I like the most, is starting with a docker container. A container helps us start up a service in the cleanest way. Once we don't want that service, just stop and remove the container.
You need to install docker on your local machine first and then start up WSO AM (API Manager) by using the below command:
docker run -d -t \-p 9443:9443 \-p 8243:8243 \-p 8280:8280 \wso2/wso2am
Wait for a short while; once the service is ready, you will be able to browse the URL: https://localhost:9443
User name and password are: admin/admin
Tada🎉🎉. Once logged in, you will see a UI like the one below:
Let's check out the process of building an API on an AM.
- Creating and publishing an API via the Publisher Portal of WSO2 API-M.
- Deploy the API in a Gateway environment.
- Publish the API in the Developer Portal.
- Subscribing to the API via the Developer Portal of WSO2 API-M and generating keys.
- Invoking the API with the generated keys.
For detail of the steps, you can refer to the document of WSO2 (API Management - WSO2 API Manager Documentation 4.1.0); I will not repeat again here. 😊
Make a simple application
Python code
Now I will make a simple application to receive the API request from the API Manager in python; let's discover how to enable that function in python. 👍
It is super short and only includes one API handler:
The HOST and PORT can be set from the environment variables. In my snippet code, I made them 0.0.0.0 and port 5000.
Let's make a test
Run it in a Docker container
Because my wso2-am is running in a Docker container, to make it able to call this API, I have to put it in another container in the same network as the wso2-am container.
From the host, copy the source file into the container
Test in the container
Publish and subscribe an API with the path to my python script
Try out the API on WSO2 AM
Hura Hura 🎉🎉🎉
We already have a simple system running with an API Gateway and a service to consume the requests from the Gateway.
You can discover yourself to learn about many features that an API Gateway like WSO2 AM can support regarding your API. Have fun 😉
See you in the next post. 🙋♂️🙋♂️
#API #APIGateway #SolutionArchitect #DevOps #Cloud