-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
26 lines (20 loc) · 863 Bytes
/
test.c
File metadata and controls
26 lines (20 loc) · 863 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
#include "httpserver.h"
#define PORT "3490\0"
void helloWorldHandler(char *response, char *requestBody)
{
char body[] = "{'information': 'Hello, World!','data': 'This is a test message'}";
printf("\nReceived request body -> %s\n", requestBody);
snprintf(response, MAX_DATA_SIZE, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %li\r\n\r\n%s", strlen(body), body);
}
void exampleHandler(char *response, char *requestBody)
{
char body[] = "{'data': 'Example'}";
printf("\nReceived request body -> %s\n", requestBody);
snprintf(response, MAX_DATA_SIZE, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %li\r\n\r\n%s", strlen(body), body);
}
int main(int argc, char **argv)
{
createPostRoute("/helloworld", helloWorldHandler);
createPostRoute("/example", exampleHandler);
runHTTPServer(PORT);
}