Sistema de microservicios usando YARP como API Gateway.
- .NET 8.0 SDK
- Docker
- Docker Compose
┌─────────────────────────────────────────┐
│ Cliente (Browser/App) │
└──────────────┬──────────────────────────┘
│ HTTP/HTTPS Request
▼
┌─────────────────────────────────────────┐
│ YARP Reverse Proxy (ASP.NET Core) │
│ ┌───────────────────────────────────┐ │
│ │ Middleware Pipeline (YARP) │ │
│ │ - Routing │ │
│ │ - Load Balancing │ │
│ │ - Transformations │ │
│ └───────────────────────────────────┘ │
│ Kestrel Server │
└──────────────┬──────────────────────────┘
│ Proxy Request
▼
┌─────────────────────────────────────────┐
│ Microservicios Backend │
│ ┌──────────┐ ┌──────────┐ ┌─────────┐ │
│ │ API 1 │ │ API 2 │ │ API 3 │ │
│ │ (Kestrel)│ │ (Kestrel)│ │(Kestrel)│ │
│ └──────────┘ └──────────┘ └─────────┘ │
└─────────────────────────────────────────┘
Cliente → API Gateway (YARP) → Orders API → Products API
┌─────────────────────────────────────────┐
│ Cliente HTTP │
│ (Browser, Postman, cURL) │
└──────────────┬──────────────────────────┘
│ http://localhost:8000
▼
┌─────────────────────────────────────────┐
│ YARP API Gateway (Port 8000) │
│ ┌───────────────────────────────────┐ │
│ │ Routing Rules: │ │
│ │ - /orders → orders-api:8080 │ │
│ │ - /products → products-api:8081 │ │
│ └───────────────────────────────────┘ │
└──────────┬──────────────┬───────────────┘
│ │
┌─────▼──────┐ ┌────▼──────┐
│ Orders API │ │ Products │
│ Port: 8080 │ │ API │
│ │ │ Port: 8081│
└────────────┘ └───────────┘
# Construir imágenes
docker-compose build
# Iniciar servicios
docker-compose up -d
# Ver logs
docker-compose logs -f
# Detener servicios
docker-compose down# Terminal 1 - Orders API
cd src/Orders.Api
dotnet run --urls "http://localhost:8080"
# Terminal 2 - Products API
cd src/Products.Api
dotnet run --urls "http://localhost:8081"
# Terminal 3 - API Gateway
cd src/ApiGateway
dotnet run --urls "http://localhost:8000"
# Info del gateway
curl http://localhost:8000
# Health check
curl http://localhost:8000/health
# Obtener todas las órdenes
curl http://localhost:8000/orders
# Obtener orden por ID
curl http://localhost:8000/orders/1
# Crear nueva orden
curl -X POST http://localhost:8000/orders \
-H "Content-Type: application/json" \
-d '{
"customerName": "Carlos Ruiz",
"totalAmount": 499.99,
"status": "Pending",
"items": [
{
"productId": 101,
"productName": "Laptop",
"quantity": 1,
"price": 499.99
}
]
}'
# Actualizar orden
curl -X PUT http://localhost:8000/orders/1 \
-H "Content-Type: application/json" \
-d '{
"customerName": "Juan Pérez Updated",
"totalAmount": 399.99,
"status": "Completed",
"items": []
}'
# Eliminar orden
curl -X DELETE http://localhost:8000/orders/1# Obtener todos los productos
curl http://localhost:8000/products
# Obtener producto por ID
curl http://localhost:8000/products/101
# Buscar por categoría
curl http://localhost:8000/products/category/Electronics
# Crear nuevo producto
curl -X POST http://localhost:8000/products \
-H "Content-Type: application/json" \
-d '{
"name": "Mechanical Keyboard",
"description": "RGB backlit keyboard",
"price": 129.99,
"stock": 30,
"category": "Accessories"
}'
# Actualizar producto
curl -X PUT http://localhost:8000/products/101 \
-H "Content-Type: application/json" \
-d '{
"name": "Laptop Dell XPS 15 Updated",
"description": "Updated description",
"price": 1199.99,
"stock": 10,
"category": "Electronics"
}'
# Eliminar producto
curl -X DELETE http://localhost:8000/products/101