コンテンツにスキップ
DocsTry Aspire
DocsTry

Connect Aspire apps to Data API Builder

このコンテンツはまだ日本語訳がありません。

⭐ Community Toolkit Data API Builder logo

This page describes how consuming apps connect to a Data API Builder resource. For configuration files, database references, image settings, and health checks, see Set up Data API Builder in the AppHost.

DAB has no dedicated Community Toolkit client package. It exposes standard REST and GraphQL endpoints, so use the HTTP or GraphQL client for your app’s language.

DataApiBuilderContainerResource implements service discovery rather than a connection string. Referencing a DAB resource named dab injects:

Environment variableDescription
services__dab__http__0Resolved URL for the DAB HTTP endpoint

The AppHost resource also exposes endpoint properties for building custom expressions. These are AppHost properties, not additional consuming-app environment variables. See Use endpoint properties for synchronized C# and TypeScript examples.

Each example calls the REST route /api/Product. Use /graphql for GraphQL requests.

Apps that use Aspire service defaults can address the resource by name:

Program.cs
builder.Services.AddHttpClient("dab", client =>
{
client.BaseAddress = new Uri("https+http://dab");
});

Or read the resolved service-discovery endpoint directly:

Program.cs
var endpoint = Environment.GetEnvironmentVariable("services__dab__http__0")
?? throw new InvalidOperationException(
"services__dab__http__0 is not set.");
using var client = new HttpClient
{
BaseAddress = new Uri(endpoint)
};
var products = await client.GetStringAsync("/api/Product");