microsoft / microsoft/aspire

Allow referencing .http file as multiple commads for a web api service

Open
#8,521 1 comment 0 reactions 0 assignees View on GitHub
needs-area-label
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

when creating new web-api projects (`dotnet new webapi`) a `.http` file is generated.

leveraging these files and being able to use them as simple aspire commands would useful for local dev.

something like this
```cs
public static class HttpCommandsFromHttpFileExtensions
{
public static IResourceBuilder WithHttpCommandsFromHttpFile(this IResourceBuilder builder)
{
builder.ApplicationBuilder.Services.AddHttpClient();
// logic that reads the *.http file and creates commands for each request

// sample command for demonstration purposes
return builder
.WithCommand("http-GET-/api/hello", "GET /api/hello", async context =>
{
var endpoint = builder.GetEndpoint("http");
var client = context.ServiceProvider.GetRequiredService();
var response = await client.GetAsync(endpoint.Url);
var logger = context.ServiceProvider.GetRequiredService().CreateLogger(context.ResourceName);
logger.LogInformation("Response received with status code: {StatusCode}", response.StatusCode);
return new ExecuteCommandResult
{
Success = response.IsSuccessStatusCode,
};
})
;
}
}
```

### Describe the solution you'd like

![Image](https://github.com/user-attachments/assets/d7761217-4bb7-46ec-8c95-15dc2b47542d)

maybe having a nested menu to allow for multiple requests 🤔

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.