This repository contains the source code and detailed instructions for implementing an API Gateway using YARP (Yet Another Reverse Proxy) in ASP.NET Core. The project demonstrates how to configure a gateway that routes requests to different microservices, enhancing the scalability and security of your application.
This repository accompanies an article written in Italian. While the code comments and variable names are in English, the full explanation and tutorial are available in Italian on the blog post linked below.
- Configuration of an API Gateway using YARP
- Routing of requests to multiple microservices
- Custom header handling to demonstrate YARP's capabilities
- Example project setup for testing the gateway
- Visual Studio 2022 or later
- .NET 7.0 SDK or later
- Basic knowledge of ASP.NET Core Web API and YARP
- Clone this repository.
- Open the solution in Visual Studio.
- Build and run both the
APIGateway
andAPIGateway.Customers
projects. - Use tools like
curl
, Postman, or Swagger UI to test the API Gateway.
- APIGateway: Contains the gateway configuration using YARP.
- APIGateway.Customers: A sample microservice with API endpoints that the gateway routes to.
- appsettings.json: Configures the routes and headers for the gateway.
The gateway project is configured to route requests to the APIGateway.Customers
project. You can customize the routing rules, headers, and other settings in the appsettings.json
file of the APIGateway
project.
- Create a new customer:
curl --location --request POST 'http://localhost:5000/customers/create?customer=nuovo%20cst'
- List all customers:
curl --location 'http://localhost:5000/customers/all'
- Extending the gateway to handle more microservices.
- Customizing YARP middleware for logging, authentication, or load balancing.
- Performance considerations when using an API Gateway.
Feel free to fork this repository, suggest improvements, and submit pull requests. Contributions that enhance the functionality or documentation are highly appreciated.
For a detailed explanation of the concepts and implementation, check out the full article (in Italian) on https://cosminirimescu.com.