Skip to content

Api-Gateway with Yarp, providing a gateway for 2 Downstream-APIs

Notifications You must be signed in to change notification settings

reiugit/ApiGatewayWithYarp

Repository files navigation

Api-Gateway with Yarp

  • AddReverseProxy
  builder.Services
      .AddReverseProxy()
      .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
  • MapReverseProxy
  app.MapReverseProxy();
  • Sample configuration in appsettings.json
  ...
  "ReverseProxy": {

    "Routes": {
      "api1-route": {
        "ClusterID": "api1-cluster",
        "Match": {
          "Path": "/api1/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "/{**catch-all}" }
        ]
      },
      "api2-route": {
        "ClusterID": "api2-cluster",
        "Match": {
          "Path": "/api2/{**catch-all}"
        },
        "Transforms": [
          { "PathPattern": "/{**catch-all}" }
        ]
      }
    },

    "Clusters": {
      "api1-cluster": {
        "Destinations": {
          "destination1": {
            "Address": "http://localhost:5001"
          }
        }
      },
      "api2-cluster": {
        "Destinations": {
          "destination1": {
            "Address": "http://localhost:5002"
          }
        }
      }
    }

  }
  ...
  • Public Urls provided by Gateway API:
  http://<gateway-api>/api1/<downstream-endpoint>
  http://<gateway-api>/api2/<downstream-endpoint>

About

Api-Gateway with Yarp, providing a gateway for 2 Downstream-APIs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages