1. Hello world¶
A complete Baldr application in a single file.
Source¶
| src/main.cpp | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
Build and run¶
terminal
cmake -S . -B build
cmake --build build --config Release
./build/my_app
In another terminal:
terminal
curl http://localhost:8080/json
Response:
Response
{ "message": "Hello, World!" }
What just happened?¶
The four lines that turn this into an HTTP server are:
skr::ApplicationBuilder()— Skirnir's generic host builder..WithExtension<baldr::BaldrExtension>()— registers Baldr's services (router, middleware provider, HTTP server)..Build<baldr::WebApplication>()— constructs the strongly-typed application.app->MapGet("/json", handler)— registers a handler forGET /json.
The handler returns a Payload aggregate, and the framework serialises it to JSON automatically with Content-Type: application/json.
Next¶
Continue with 2. Routing and results.