Examples¶
The examples/ directory contains small, runnable programs that demonstrate individual features of Baldr. Each example is a self-contained CMake target built when Baldr is the top-level project.
Browse by topic¶
-
Hello World
The smallest possible Baldr program — one route, automatic JSON.
-
Hello Service
Register a service and inject it into a route handler.
-
Devices
Return a list of
Devicerecords. -
Weather forecast
Generate a random forecast and return it as JSON.
-
Static files
Serve a directory tree under a URL prefix using
MapStaticFiles. -
File stream
Stream a file download and accept an upload, using
FileStreamResultandResults::Json. -
OpenAPI example
Generate a 3.0.3 spec from route metadata with
BaldrOpenApiExtension. -
Todo
A small CRUD service: DI-registered repository, controller with grouped routes,
FromParams/FromBodybinding, and OpenAPI.
Building the examples¶
When Baldr is the top-level project, examples are built by default:
cmake -S . -B build
cmake --build build
Each example produces an executable named after its directory: ./build/HelloWorld, ./build/HelloService, ./build/Devices, ./build/WeatherForecast, ./build/StaticFiles, ./build/FileStream, ./build/OpenApiExample, ./build/Todo.
To disable examples (for example in a production build), set -DBALDR_BUILD_EXAMPLES=OFF at configure time.