#include "include/mongoose.h" #include "include/array.h" static void api_handler(struct mg_connection *c, int ev, struct mg_http_message *hm) { mg_http_reply(c, 200, "", "%s : %.*s", "api route response", hm->uri.len, hm->uri.buf); } static void ev_handler(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *)ev_data; array_mg_str path_array = {0}; split_mg_str(&hm->uri, '/', &path_array); if (path_array.count > 0) { if (mg_match(path_array.items[0], mg_str("api"), NULL)) { api_handler(c, ev, hm); return; } } mg_http_reply(c, 200, "", "%s", "Hello world"); } } int main() { struct mg_mgr mgr; mg_mgr_init(&mgr); mg_http_listen(&mgr, "http://0.0.0.0:8000", ev_handler, NULL); for (;;) { mg_mgr_poll(&mgr, 100); } return 0; }