Skip to content

Add support for expressing existing external HTTP services as resources in the hosting project #775

@DamianEdwards

Description

@DamianEdwards

Scenario is I have an external HTTP service that I want to connect to (similar to an existing Redis instance or existing PostgreSQL instance) so I want to model it in my hosting project so that other resources can reference it and have service discovery configured so they can refer to it by the name I give it.

e.g.
MyApp.AppHost/Program.cs

var builder = DistributedApplication.CreateBuilder(args);

var weatherApi = builder.AddHttpService("weatherapi", "http://weather.internal.sda76erh.us.contoso.com");

builder.AddProject<Projects.Frontend>("frontend")
    .WithReference(weatherApi);

builder.Build().Run();

MyApp.Frontend/Program.cs

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

builder.Services.AddHttpClient("weather", c => c.BaseAddress = new("http://weatherapi"));

var app = builder.Build();

app.MapGet("/", async (IHttpClientFactory hcf) => await hcf.CreateClient("weather").GetStringAsync("/weatherforecast"));

app.MapDefaultEndpoints();

app.Run();

Metadata

Metadata

Assignees

Labels

area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationhelp wantedIssue that is a good candidate for community contribution.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions