-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
30 lines (21 loc) · 807 Bytes
/
Copy pathtest.c
File metadata and controls
30 lines (21 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#define _POSIX_C_SOURCE 200809L
#include <unistd.h>
#include "src/http-router.h"
static void route_home_handler(int client_socket) {
const char *body = "<html><body>Home</body></html>";
http_router_write(client_socket, 200, "Content-Type: text/html\r\n", body);
close(client_socket);
}
static void route_test_handler(int client_socket) {
const char *body = "<html><body>Test</body></html>";
http_router_write(client_socket, 200, "Content-Type: text/html\r\nX-Powered-By: C\r\n", body);
close(client_socket);
}
int main(void) {
Router *router = http_router_new();
http_router_add(router, "GET", "/", route_home_handler);
http_router_add(router, "GET", "/test", route_test_handler);
http_router_run(router, 8080);
http_router_stop(router);
return 0;
}