Convert to api
Thu Mar 07 2024 20:59:25 GMT+0000 (Coordinated Universal Time)
Saved by
@darkoeller
/ Existing Blazor project: Program.cs (Startup class)
public void ConfigureServices(IServiceCollection services)
{
// ... other service registrations
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My Blazor API", Version = "v1" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ... other configuration
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Blazor API v1");
});
app.MapGet("/api/weather", async (httpContext) =>
{
// Fetch weather data from your service
var forecasts = await _weatherService.GetForecasts();
await httpContext.Response.WriteAsJsonAsync(forecasts);
});
content_copyCOPY
https://gemini.google.com/
Comments