-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (39 loc) · 1.12 KB
/
Program.cs
File metadata and controls
51 lines (39 loc) · 1.12 KB
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
using Xavier.Extensions;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Add Xavier with one line!
builder.AddXavier(options =>
{
// Optionally customize options
options.HttpLogging.Enabled = true; // Enable HTTP logging
});
WebApplication app = builder.Build();
// Use Xavier middleware
app.UseXavier();
// Map infrastructure endpoints (health, OpenAPI)
app.MapXavierInfrastructureEndpoints();
// Your API endpoints
app.MapGet("/", () => "Hello from Xavier!");
app.MapGet("/api/users", () => new[]
{
new { Id = 1, Name = "Alice" },
new { Id = 2, Name = "Bob" }
});
app.MapGet("/api/users/{id}", (int id) =>
{
if (id <= 0)
{
return Results.NotFound();
}
return Results.Ok(new { Id = id, Name = $"User {id}" });
});
app.MapPost("/api/users", (UserRequest request) =>
{
return Results.Created($"/api/users/3", new { Id = 3, Name = request.Name });
});
// This will throw an exception to demonstrate ProblemDetails
app.MapGet("/api/error", () =>
{
throw new InvalidOperationException("This is a test exception!");
});
app.Run();
record UserRequest(string Name);