common.h 659 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // Created by Don Goodman-Wilson on 15/04/2017.
  3. //
  4. #pragma once
  5. #include <luna/luna.h>
  6. #include <nlohmann/json.hpp>
  7. using json = nlohmann::json;
  8. // Request handlers
  9. // /json
  10. auto json_handler = [](auto req) -> luna::response {
  11. json j;
  12. j["message"] = "Hello, World!";
  13. return {
  14. 200,
  15. luna::response_headers{{"Server", "luna"}},
  16. "application/json",
  17. j.dump(),
  18. };
  19. };
  20. // /plaintext
  21. auto plaintext_handler = [](auto req) -> luna::response {
  22. return {
  23. 200,
  24. luna::response_headers{{"Server", "luna"}},
  25. "text/plain",
  26. "Hello, world!",
  27. };
  28. };