sample.cc 745 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // sample.cc
  3. //
  4. // Copyright (c) 2012 Yuji Hirose. All rights reserved.
  5. // The Boost Software License 1.0
  6. //
  7. #include <httpsvrkit.h>
  8. #include <cstdio>
  9. int main(void)
  10. {
  11. using namespace httpsvrkit;
  12. Server svr;
  13. svr.post("/", [](const Request& /*req*/, Response& res) {
  14. res.body_ = "<html><head></head><body><ul></ul></body></html>";
  15. });
  16. svr.post("/item", [](const Request& req, Response& res) {
  17. res.body_ = req.pattern_;
  18. });
  19. svr.get("/item/:name", [](const Request& req, Response& res) {
  20. try {
  21. res.body_ = req.params_.at("name");
  22. } catch (...) {
  23. // Error...
  24. }
  25. });
  26. svr.run("0.0.0.0", 1234);
  27. }
  28. // vim: et ts=4 sw=4 cin cino={1s ff=unix