Your first application
The smallest possible Garvan program is just a few lines of C++. Let's walk through what each part does.
1. Include
Start an empty main.cpp and pull in the Garvan-bundled Crow header:
#include "vendors/Garvan/crow.h"
This single header exposes crow::SimpleApp, the routing macros, the JSON value types, and the mustache template engine.
2. App declaration
Declare a Crow application inside main():
int main()
{
crow::SimpleApp app;
}
SimpleApp holds the HTTP server, the router, and the logger. Use crow::App<M1, M2, ...> instead when you need middlewares attached at the application level — see the middleware guide.
3. Adding routes
A route binds a URL pattern to a handler. The CROW_ROUTE macro is the most common way:
CROW_ROUTE(app, "/")([] {
return "Hello from Garvan!";
});
The lambda is called whenever a client requests GET /. Returning a std::string sends it back as the response body.
4. Running the app
Pick a port and start the server:
app.port(9090).multithreaded().run();
multithreaded() tells Crow to use one worker per CPU core. run() blocks until the process is terminated; use run_async() if you need to do other work alongside the server.
Full example
#include "vendors/Garvan/crow.h"
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")([] {
return "Hello from Garvan!";
});
app.port(9090).multithreaded().run();
}
Build it and visit http://localhost:9090 — you should see the greeting in your browser.