-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
53 lines (42 loc) · 1.24 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var builder = WebApplication.CreateBuilder(args);
// Add swagger
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
// This isn't how you usually do this in .NET. See options-patterns instead.
var favoriteLunch = Environment.GetEnvironmentVariable("FAV_LUNCH");
var machineName = Environment.MachineName;
var isHealthy = true;
app.MapGet("/info", () =>
{
if (isHealthy)
return new
{
newField = "Some new field",
majorNewField = "Nope I'm a captain",
favoriteLunch,
machineName
};
throw new Exception("Sorry I am broken :(");
})
.WithName("SystemInfo")
.WithOpenApi();
// Boss said we needed this done ASAP
app.MapPost("/experimental", () =>
{
isHealthy = false;
return "I think this went OK";
}).WithName("BETA: Experimental feature")
.WithOpenApi();
// Endpoint to probe weather or not this API is working properly
app.MapGet("/health", () =>
{
if (isHealthy) return "OK";
throw new Exception("OH NO I AM UNHEALTHY");
})
.WithName("Health")
.WithOpenApi();
app.Run();