Creating an API Gateway using Ocelot.NET & ASP.NET Core (.NET 5)

Tutorial Content

  • Creating a simple rest application to act as our downstream application. (Web API Template)
  • Creating the API Gateway which forwards the request to the downstream sample application.

Prerequisites

  • IDE of Choice
  • .NET Core 3.1 or .NET 5 SDK (Asp.net Core)

Creating the Sample Application

If you’re using Visual Studio or Rider this should be quite easy, all you have to do is to create a default ASP.NET Core project using the Web API template.

Creating the API Gateway

  1. Create an empty ASP.NET Core Web Project.
  2. Install the Ocelot Nuget package
{
"Routes": [
{
"DownstreamPathTemplate": "/WeatherForecast",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5000
}
],
"UpstreamPathTemplate": "/api/weather" ,
"UpstreamHttpMethod": [ "Get" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5003"
}
}
"applicationUrl": "https://localhost:5003;http://localhost:5002",

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