mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 09:18:27 +00:00
Added Context struct.
This commit is contained in:
parent
3464386f17
commit
277d7c0854
2 changed files with 66 additions and 33 deletions
|
@ -14,17 +14,17 @@ int main(void)
|
|||
|
||||
Server svr;
|
||||
|
||||
svr.post("/", [](const Request& /*req*/, Response& res) {
|
||||
res.body_ = "<html><head></head><body><ul></ul></body></html>";
|
||||
svr.get("/", [](Context& cxt) {
|
||||
cxt.response.body = "<html><head></head><body><ul></ul></body></html>";
|
||||
});
|
||||
|
||||
svr.post("/item", [](const Request& req, Response& res) {
|
||||
res.body_ = req.pattern_;
|
||||
svr.post("/item", [](Context& cxt) {
|
||||
cxt.response.body = cxt.request.pattern;
|
||||
});
|
||||
|
||||
svr.get("/item/:name", [](const Request& req, Response& res) {
|
||||
svr.get("/item/:name", [](Context& cxt) {
|
||||
try {
|
||||
res.body_ = req.params_.at("name");
|
||||
cxt.response.body = cxt.request.params.at("name");
|
||||
} catch (...) {
|
||||
// Error...
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue