Skip to content

Latest commit

 

History

History
66 lines (59 loc) · 1.27 KB

README.md

File metadata and controls

66 lines (59 loc) · 1.27 KB

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>