This library contains simple implementation of the YARP configuration provider persisted in memory. It should be used for simple API Gateway scenarios, usually when designing solutions written in BFF pattern.
enum ServiceType
{
HELLO,
USERS
}
var routes = new List<RouteConfig>
{
RouteConfigBuilder.Builder.WithId("users-all").ToService(ServiceType.USERS).WithPathMatch("/api/users", true).Build(),
RouteConfigBuilder.Builder.WithId("hello").ToService(ServiceType.HELLO).WithPathMatch("/api/hello").Build()
} as IReadOnlyList<RouteConfig>;
var servicesUrls = new Dictionary<ServiceType, string> {
{ ServiceType.HELLO, "https://localhost:10001" },
{ ServiceType.USERS, "https://localhost:20000" }
} as IReadOnlyDictionary<ServiceType, string>;
services.AddReverseProxy()
.LoadFromMemory(routes, servicesUrls);
Above code will add in memory configuration provider and proxy would:
- redirect everything that matches /api/users (for example
/api/users
,/api/users/some/path
tolocalhost:20000/{REQUEST_PATH}
) - redirect exactly
/api/hello
tolocalhost:100001/api/hello
If you have any issues, problems, questions, feel free to open an issue on GitHub.