test_simple.cpp 766 B

1234567891011121314151617181920212223242526
  1. #include "test_simple.h"
  2. #include <cppcms/http_response.h>
  3. #include <cppcms/url_dispatcher.h>
  4. #include <cppcms/json.h>
  5. #include <ctime>
  6. test_simple::test_simple(cppcms::service &s) : cppcms::application(s) {
  7. dispatcher().assign("/json", &test_simple::servre_json, this);
  8. dispatcher().assign("/plaintext", &test_simple::servre_plaintext, this);
  9. }
  10. void test_simple::servre_json() {
  11. response().content_type("application/json");
  12. cppcms::json::value my_object;
  13. my_object["message"] = "Hello, World!";
  14. response().date(std::time(nullptr));
  15. response().out() << my_object;
  16. }
  17. void test_simple::servre_plaintext() {
  18. response().content_type("text/plain");
  19. response().date(std::time(nullptr));
  20. response().out() << "Hello, World!";
  21. }