comparison 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
comparison
equal deleted inserted replaced
71:75de5903355c 72:4532ce6d9eb8
1 /**
2 *
3 * MrJuneJune
4 *
5 * - Server side generated my blog created using entirely in C.
6 * - Resume
7 * - What have I done?
8 * - Blogs....
9 *
10 */
11
12 #include "seobeo/seobeo.h" 1 #include "seobeo/seobeo.h"
13 2
14 volatile sig_atomic_t stop_server = 0; 3 volatile sig_atomic_t stop_server = 0;
15 4
16 void handle_sigint(int sig) { 5 void handle_sigint(int sig)
6 {
17 printf("Failed\n"); 7 printf("Failed\n");
18 stop_server = 1; 8 stop_server = 1;
19 } 9 }
20 10
11 Seobeo_Request_Entry* GetUser(Seobeo_Request_Entry *req, Dowa_Arena *arena)
12 {
13 void *id_kv = Dowa_HashMap_Get_Ptr(req, ":id");
14 const char *user_id = id_kv ? ((Seobeo_Request_Entry*)id_kv)->value : "unknown";
15
16 Seobeo_Request_Entry *resp = NULL;
17 char *body = Dowa_Arena_Allocate(arena, 256);
18 snprintf(body, 256, "{\"id\":\"%s\",\"name\":\"John Doe\"}", user_id);
19
20 Dowa_HashMap_Push_Arena(resp, "body", body, arena);
21 return resp;
22 }
23
24
21 int main(void) 25 int main(void)
22 { 26 {
27 Seobeo_Router_Init();
28 Seobeo_Router_Register("GET", "/v1/users/:id", GetUser);
23 Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2); 29 Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2);
24 } 30 }