sample.cc 642 B

1234567891011121314151617181920212223242526272829303132
  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. cxt.response.body = cxt.request.params.at("name");
  21. });
  22. svr.run("localhost", 1234);
  23. }
  24. // vim: et ts=4 sw=4 cin cino={1s ff=unix