Creating an API Gateway using Ocelot.NET and Consul in ASP.NET Core (.NET 5) with Docker


Tutorial Content

1 Deploying Consul using Docker Desktop

docker run -d — name=dev-consul -p 8500:8500 -p 8600:8600 — restart unless-stopped consul
docker container list
docker container list — results

2 Creating a sample API and registering it with Consul

Visual Studio Project Settings
app.UseEndpoints(endpoints =>{  endpoints.MapHealthChecks(“/health”);
docker build -t sampleapi .docker run sampleapi
Consul showing our SampleAPI

3 Creating the API Gateway using Ocelot.NET and integrating Consul

docker build -t apigateway.docker run apigateway -p <HOSTPORT>:80
launchSettings.json Docker section
WeatherForecast results from our API Gateway

Short Coding Tutorials for .NET & NodeJS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store