http_server_test.cpp 494 B

123456789101112131415161718192021
  1. #include "HttpServer.h"
  2. int main() {
  3. HttpService service;
  4. service.GET("/ping", [](HttpRequest* req, HttpResponse* resp) {
  5. resp->body = "pong";
  6. return 200;
  7. });
  8. service.POST("/echo", [](HttpRequest* req, HttpResponse* resp) {
  9. resp->content_type = req->content_type;
  10. resp->body = req->body;
  11. return 200;
  12. });
  13. http_server_t server;
  14. server.port = 8080;
  15. server.service = &service;
  16. http_server_run(&server);
  17. return 0;
  18. }