-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjson.c
More file actions
35 lines (30 loc) · 735 Bytes
/
Copy pathjson.c
File metadata and controls
35 lines (30 loc) · 735 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
31
32
33
34
35
#include <err.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <kcgi.h>
#include <kcgijson.h>
int
main(void)
{
struct kreq r;
struct kjsonreq req;
const char *page = "index";
if (khttp_parse(&r, NULL, 0, &page, 1, 0) != KCGI_OK)
return EXIT_FAILURE;
if (pledge("stdio", NULL) == -1)
err(EXIT_FAILURE, "pledge");
khttp_head(&r, kresps[KRESP_STATUS],
"%s", khttps[KHTTP_200]);
khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
"%s", kmimetypes[r.mime]);
khttp_body(&r);
kjson_open(&req, &r);
kjson_obj_open(&req);
kjson_putstringp(&req, "greeting", "hello, world");
kjson_obj_close(&req);
kjson_close(&req);
khttp_free(&r);
return EXIT_SUCCESS;
}