forked from HapticX/happyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testc16.nim
103 lines (81 loc) · 1.85 KB
/
testc16.nim
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import
../src/happyx
var x = generate_password("secret")
echo "secret".check_password(x)
echo "secret1".check_password(x)
model TestModel:
username: string
password: string
model TestModel1:
username: string
password: string
model User:
id: int
model Message:
text: string
user: User
model Generics{JSON}[T]:
field1: T
mount Profile:
get "/":
## Profile main page
return "Hello, world!"
get "/settings":
## Profile settings
return "Hello, world"
post "/settings":
## Update profile settings
return "Hello, world!"
serve "127.0.0.1", 5000:
mount "/profile" -> Profile
"/some":
## Hello, world
return "Hi"
get "/calculate/$left:float/$operator:string/$right?:float":
## Some
echo left
echo right
return fmt"{left + right}"
get "/auth[model:TestModel:json]":
## User authorization
return "Hello, world!"
get "/arrQuery":
## Parses array and simple queries
return {
"arr": queryArr?a,
"val": query?b
}
ws "/Hello":
discard
get "/":
## Set bestFramework to **"HappyX!"** in cookies
##
## ```nim
## echo "Hello, world!"
## ```
##
## Responds "Hello, world!"
echo inCookies
outCookies.add(setCookie("bestFramework", "HappyX!", secure = true, httpOnly = true))
return "Hello, world!"
get "/setStatusCode":
## Responds "Hello, world!" with 404 HttpCode
statusCode = 404
if true:
if true:
for i in 0..1:
if true:
when true:
statusCode = 400
return 1
return "Hello, world!"
get "/headers":
outHeaders["Test"] = 10
outHeaders["HappyXHeader"] = "Hello"
return "Hello, world!"
post "/post":
## Creates a new post
return "Hello, world!"
put "/post/$id:int":
## Edits a post
return "Hello, world!"