-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathhello_world.cpp
More file actions
executable file
·17 lines (17 loc) · 783 Bytes
/
Copy pathhello_world.cpp
File metadata and controls
executable file
·17 lines (17 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Copyright 2026 Sebastiano Merlino
// libhttpserver hello-world example — the lambda form.
// Compiles in ten lines including main(), with no http_resource subclass
// and no raw-pointer ownership. Production code typically qualifies names
// explicitly; the `using namespace` here is a one-off so this file can
// document the shortest possible end-to-end demo. See shared_state.cpp
// for the class-based pattern that is appropriate when handlers must
// share mutable state.
#include <httpserver.hpp>
using namespace httpserver; // NOLINT(build/namespaces) - keep the demo at <=10 LOC
int main() {
webserver ws{create_webserver(8080)};
ws.on_get("/hello", [](const http_request&) {
return http_response::string("Hello, World!");
});
ws.start(true);
}