1
0
mirror of synced 2025-04-21 22:25:55 +03:00
cpp-httplib/example/sample.cc
2012-09-23 00:40:46 -04:00

37 lines
745 B
C++

//
// sample.cc
//
// Copyright (c) 2012 Yuji Hirose. All rights reserved.
// The Boost Software License 1.0
//
#include <httpsvrkit.h>
#include <cstdio>
int main(void)
{
using namespace httpsvrkit;
Server svr;
svr.post("/", [](const Request& /*req*/, Response& res) {
res.body_ = "<html><head></head><body><ul></ul></body></html>";
});
svr.post("/item", [](const Request& req, Response& res) {
res.body_ = req.pattern_;
});
svr.get("/item/:name", [](const Request& req, Response& res) {
try {
res.body_ = req.params_.at("name");
} catch (...) {
// Error...
}
});
svr.run("0.0.0.0", 1234);
}
// vim: et ts=4 sw=4 cin cino={1s ff=unix