If you want to develop an application in cloud environment and want to implement micro-services architecture pattern then sooner or later you will face with API Gateways. There are many API Gateway outside that we can use it and in terms of open source such as Kong, KrakenD, Tyk. In this session, I will use KrakenD API Gateway on Docker to implement API Gateway. As an example, I will use https://jsonplaceholder.typicode.com for accessing data through KrakenD as API Gateway.
For KrakenD documentation, you can read it from here
For JSONPlaceholder guide, you can read it from here
Configuration KrakenD Gateway
To configure KrakenD json gateway can be done by using KrakenD designer. You can design and download the file configuration easily by online.
KrakenD API Gateway designer
Here is some endpoint that I have made it through KrakenD API gateway designer
Endpoint in KrakenD designer
Route Mapping
I download it the file and rename it with krakend.json shown as below
Installing Docker
Installing docker on Windows is easy, you just downloaded the binary and install it by following the instruction. I have installed Docker Desktop on my windows and it is including docker compose.
My Docker version shown as below:
C:\>docker --version
Docker version 20.10.22, build 3a2c30b
C:\>docker-compose version
Docker Compose version v2.15.1
Dockerfile as below
Implementing
Create a new folder with name krakend then copy Dockerfile and krakend.json into that folder.
From folder krakend, run this command:
docker build . -t api-gateway-v1
Make sure your port setting is the same as krakend.json
docker run -it -p "8080:8080" api-gateway-v1
Docker desktop will create the container and images as shown as below
Testing
To check KrakenD is running well, it can be done by inputting
http://localhost:8080/__health
to your browser, shown as below
KrakenD is running well
To check the endpoint KrakenD, it can be done in browser by inputting
http://localhost:8080/v1/api/posts
To check another endpoint by inputting
http://localhost:8080/v1/api/posts/1
Summary
I think KrakenD has bright future. All features that you need in API Gateway is covered by KrakenD. If you have any problem in implementing KrakenD, they have very good community to support you. I hope this article will help you in implementing KrakenD. Thank you
No comments:
Post a Comment