-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
53 lines (42 loc) · 942 Bytes
/
example.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <c-natra.h>
get("/") {
html("<h1>Hello, World!</h1>");
return HTTP_OK;
}
get("/private") {
set_header("Location", "/login");
return HTTP_FOUND;
}
get("/login") {
html("<h1>Please log in</h1>");
return HTTP_OK;
}
put("/user/:name") {
html("<p>User '%s' created.</p>", params("name"));
return HTTP_CREATED;
}
get("/api") {
json("{\"stuff\": %d}", 42);
return HTTP_OK;
}
get("/template") {
view("index.html", map("title", "Template test",
"body", "<h1>Success!</h1>"));
return HTTP_OK;
}
get("/blog") {
view("blog.html", map("title", "On the usage of spinlocks in "
"ULTRIX and System V",
"body", "<h1>On the usage of spinlocks in"
" ULTRIX and System V</h1>"));
return HTTP_OK;
}
get("/search") {
html("<h1>Searching for %s ...</h1>", query("q"));
return HTTP_OK;
}
post("/gimme") {
html("<p>First eight chars posted: %s</p>", fetch(8));
return HTTP_OK;
}
serve(8000)