using Ocelot.DependencyInjection;
using Ocelot.Middleware;
var builder = WebApplication.CreateBuilder(args);
// Add services to the IoC container.
// Load the Ocelot configuration file, which defines routes and
// downstream services.
builder.Configuration.AddJsonFile("ocelot.json");
// Register Ocelot services into the DI container.
builder.Services.AddOcelot();
var app = builder.Build();
// Enables Ocelot's middleware to intercept and forward incoming
// HTTP requests.
await app.UseOcelot();
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy",
"Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
});
app.Run();
internal record WeatherForecast(DateOnly Date, int TemperatureC,
string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}