Hello World example¶
examples/HelloWorld is the smallest possible Baldr program — one route that returns a JSON payload.
Source¶
examples/HelloWorld/src/main.cpp:
| examples/HelloWorld/src/main.cpp | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
What it shows¶
- Application composition with
skr::ApplicationBuilderandbaldr::BaldrExtension. - Building the host with
builder.Build<baldr::WebApplication>(). - Route registration with
MapGet(path, handler). - Automatic JSON serialization of a returned aggregate —
Payloadis serialised to{"message":"Hello, World!"}withContent-Type: application/json.
Try it¶
cmake -S . -B build
cmake --build build
./build/HelloWorld
In another terminal:
curl http://localhost:8080/json
Next steps¶
- See Hello Service for the DI version of this program.
- Browse all examples.