Ocelot is an open-source API Gateway that is built on the .NET platform. It's meant to help us make a single starting point for our microservices-based apps. Ocelot's primary goal is to make sending requests to suitable servers easier. It also has features like authentication, load sharing, and service discovery.
Tahir Naushad, a software worker at Microsoft, first put out Ocelot in 2016. It has since become one of the most famous API Gateway solutions for .NET-based microservices and has been used by many people in the .NET community.
If you have a microservices-based design and want to make a single entry point for all your services, you can use Ocelot. Ocelot can make sending requests to the right microservices easier by routing and sending them. It also has features like authentication, load sharing, and service discovery.
As an API Gateway option built on the .NET platform, Ocelot is the best choice because it is small and easy to use. It's meant to help developers make a single starting point for their microservices-based apps. Some extra features that Ocelot offers, like load sharing, service discovery, and authentication, can make sending requests to the right microservices easier.
How to use
Start by adding the package:
dotnet add package Ocelot
Add to the Program.cs:
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
...
builder.Services.AddOcelot();
builder.Configuration.AddJsonFile("ocelot.json");
...
var app = builder.Build();
await app.UseOcelot();
Create a JSON config file:
{
"Routes": [
{
"DownstreamPathTemplate": "/api/{everything}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "exampleinternalapi.com",
"Port": 443
}
],
"UpstreamPathTemplate": "/internal/{everything}",
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
}
]
}
Run Your Application
When you run your application, it will begin listening for requests and routing them according to your Ocelot configuration.
This is a basic setup. Ocelot supports more advanced features such as authentication, load balancing, and caching, which you may want to investigate depending on your use case.
GitHub https://github.com/ThreeMammals/Ocelot