sample.cc 715 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.get("/", [](Context& cxt) {
  14. cxt.response.body = "<html><head></head><body><ul></ul></body></html>";
  15. });
  16. svr.post("/item", [](Context& cxt) {
  17. cxt.response.body = cxt.request.pattern;
  18. });
  19. svr.get("/item/:name", [](Context& cxt) {
  20. try {
  21. cxt.response.body = cxt.request.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