Building Micro Services with .Net Core + Krakend API Gateway
Having an API gateway is one of the standard of building micro services. There are many open source and enterprise version gateways available in market. In terms of open source, Ocelot, Kong, Tyk are few of the popular gateways. Especially for .NET Core Web API projects, Ocelot is kind of goto framework.
While searching for fastest and reliable open source API Gateway, I stumbled upon KrakenD API gateway which is written in Go language. On their website, you can see the performance comparison with Kong and Tyk which is pretty impressive.
.NET Core Web API Micro services with KrakenD Gateway
So to give it a try, I have built two services — UsersService and ProductsService in .NET Core 2.2 with basic CRUD operations and exposed their endpoints via KrakenD gateway. For sake of simplicity, I won’t go into how to write Web API services and DI of data services etc.
Refer to source code and README file in below repository to explore more.
Contribute to ultrasonicsoft/NetCore-MicroServices-Krakend-api-gateway-demo development by creating an account on…
Configuration of KrakenD gateway
- Online API Gateway Designer KrakenD has online designer where you can work with your configuration if you prefer not to edit configuration file. You can download configuration from editor and/or upload file to modify it.
Let’s understand a simple API gateway route mapping. In below gist, you can see that endpoint “/users” is mapped with “/api/users” backend endpoint.
- endpoint: This is endpoint used with gateway address
- output_encoding: type of output encoding. Note that, if your backend doesn’t sends any response set this value to “no-op” otherwise you will get an error.
- backend: Configuration for your backend API.
- backend/host: Address of downstream service
- backend/url_pattern: endpoint of downstream service to hit
- backend/is_collection: if downstream service sends an array of objects then this property should be set.
- backend/encoding: type of output encoding. Note that, if your backend doesn’t sends any response set this value to “no-op” otherwise you will get an error.
I think KrakenD has bright future. Their enterprise product and services looks promising. Based on open source community feedback and usage, I hope they will keep adding more features and support for community edition as well.