Working with a good technical architecture you’ll soon need to work with an API Gateway. There are many industrial solutions for large scale system giving full control and logging, such as Apigee or Software AG, but these, of course, cost a business
In this article, I’ll look at possible homegrown API’s within ASP.NET Core, which give you a lot of features without the need to pay third parties.
A very basic API Gateway can be found from Mircea Oprea:
However, a more production-ready API Gateway to look at is Ocelot
Ocelot is a .NET API Gateway. The project is aimed at people using .NET running a micro services/service-oriented architecture that need a unified point of entry into their system. It will work with anything that speaks HTTP and run on any platform that ASP.NET Core supports.
It has easy integration with IdentityServer reference and bearer tokens.
Ocelot manipulates the HttpRequest object into a state specified by its configuration until it reaches a request builder middleware where it creates a HttpRequestMessage object which is used to make a request to a downstream service. The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware. The response from the downstream service is retrieved as the requests go back up the Ocelot pipeline.
There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client. That is basically it with a bunch of other features!
A quick list of Ocelot’s capabilities for more information see the documentation.
- Request Aggregation
- Service Discovery with Consul & Eureka
- Service Fabric
- Rate Limiting
- Retry policies / QoS
- Load Balancing
- Logging / Tracing / Correlation
- Headers / Method / Query String / Claims Transformation
- Custom Middleware / Delegating Handlers
- Configuration / Administration REST API
- Platform / Cloud Agnostic