Ejemplo simple de arquitectura con API Gateway y microservicios utilizando Node.js, Express y http-proxy-middleware.
Este ejemplo demuestra cómo un API Gateway puede actuar como punto de entrada único para múltiples microservicios.
Cliente
↓
API Gateway (3000)
↓
┌───────────────┬───────────────┐
↓ ↓
Products Service Orders Service
(3001) (3002)
git clone <URL_DEL_REPOSITORIO>
cd api_gateway_examplenpm installAbrir 3 terminales diferentes.
node products-service.jsnode orders-service.jsnode gateway.jsEl API Gateway valida un token simple mediante el header:
Authorization: mitoken
curl -H "Authorization: mitoken" http://localhost:3000/productoscurl -H "Authorization: mitoken" http://localhost:3000/ordenescurl -X POST http://localhost:3000/ordenes \
-H "Authorization: mitoken" \
-H "Content-Type: application/json" \
-d '{"usuario":"Laura","producto":"Camisa"}'