Usage overview¶
A Baldr application is built around three concepts:
- An application builder (provided by Skirnir) that wires up services and extensions.
- The Baldr extension, which registers the router, middleware provider, and HTTP server with the builder.
- The web application, which exposes a strongly-typed API for registering routes and running the server.
The minimal program¶
The smallest possible Baldr application looks like this:
| src/main.cpp | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
See the Hello World example for the complete project layout.
Application lifecycle¶
A Baldr program follows this lifecycle:
- Configure services — register custom services on the builder's service collection.
- Add extensions — call
.WithExtension<BaldrExtension>()to wire up the router and HTTP server. - Build the application —
.Build<WebApplication>()resolves all services and constructs the app. - Register routes — call
MapGet,MapPost, or other mapping helpers. - Run —
app->Run()starts the HTTP listener and blocks until shutdown.
Where to go next¶
-
Routing
Map routes, read parameters, and return responses.
-
Dependency injection
Register and resolve services from the container.
-
Middleware
Intercept requests with composable middleware.