fork download
  1. #include <iostream>
  2. #include <native/native.h>
  3. #include <cstdio>
  4. #include <cstring>
  5. //using namespace native::http;
  6.  
  7. using native::http::http;
  8. using native::http::response;
  9. using native::http::request;
  10. using native::http::url_obj;
  11. using native::run;
  12.  
  13. int main() {
  14. http server;
  15. unsigned short port = 8080;
  16. if(!server.listen("0.0.0.0", port, [](request& req, response& res) {
  17. std::cout << "req.url().path() = " << req.url().path();
  18. if (true) { //strcmp(req.url().path() == "/foo")) {
  19. std::string body = req.get_body();
  20. res.set_status(200);
  21. res.set_header("Content-Type", "application/json");
  22. res.end(req.url().path()); // Easy way to print current route
  23. } else {
  24. std::string body = req.get_body();
  25. res.set_status(201);
  26. res.set_header("Content-Type", "application/json");
  27. res.end("{\"bar\": \"foo\"}");
  28. }
  29. })) return 1; // Failed to run server.
  30.  
  31. std::cout << "Server running at http://0.0.0.0:" << port << "/" << std::endl;
  32. return run();
  33. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:27: fatal error: native/native.h: No such file or directory
 #include <native/native.h>
                           ^
compilation terminated.
stdout
Standard output is empty