Mercurial
diff mrjunejune/main.c @ 72:4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 29 Dec 2025 07:50:07 -0800 |
| parents | 84672efec192 |
| children | c348ac875294 |
line wrap: on
line diff
--- a/mrjunejune/main.c Sun Dec 28 20:34:22 2025 -0800 +++ b/mrjunejune/main.c Mon Dec 29 07:50:07 2025 -0800 @@ -1,24 +1,30 @@ -/** - * - * MrJuneJune - * - * - Server side generated my blog created using entirely in C. - * - Resume - * - What have I done? - * - Blogs.... - * - */ - #include "seobeo/seobeo.h" volatile sig_atomic_t stop_server = 0; -void handle_sigint(int sig) { +void handle_sigint(int sig) +{ printf("Failed\n"); stop_server = 1; } +Seobeo_Request_Entry* GetUser(Seobeo_Request_Entry *req, Dowa_Arena *arena) +{ + void *id_kv = Dowa_HashMap_Get_Ptr(req, ":id"); + const char *user_id = id_kv ? ((Seobeo_Request_Entry*)id_kv)->value : "unknown"; + + Seobeo_Request_Entry *resp = NULL; + char *body = Dowa_Arena_Allocate(arena, 256); + snprintf(body, 256, "{\"id\":\"%s\",\"name\":\"John Doe\"}", user_id); + + Dowa_HashMap_Push_Arena(resp, "body", body, arena); + return resp; +} + + int main(void) { + Seobeo_Router_Init(); + Seobeo_Router_Register("GET", "/v1/users/:id", GetUser); Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2); }