7
7
websocket = WS (app , "/web_socket" )
8
8
i = - 1
9
9
10
+
10
11
@websocket .on ("message" )
11
12
async def connect ():
12
13
global i
13
- i += 1
14
- if i == 0 :
14
+ i += 1
15
+ if i == 0 :
15
16
return "Whaaat??"
16
- elif i == 1 :
17
+ elif i == 1 :
17
18
return "Whooo??"
18
- elif i == 2 :
19
+ elif i == 2 :
19
20
i = - 1
20
21
return "*chika* *chika* Slim Shady."
21
22
23
+
22
24
@websocket .on ("close" )
23
25
def close ():
24
26
return "GoodBye world, from ws"
25
27
28
+
26
29
@websocket .on ("connect" )
27
30
def message ():
28
31
return "Hello world, from ws"
@@ -47,10 +50,12 @@ async def test(request):
47
50
48
51
return static_file (html_file )
49
52
53
+
50
54
@app .get ("/jsonify" )
51
55
async def json_get ():
52
56
return jsonify ({"hello" : "world" })
53
57
58
+
54
59
@app .get ("/query" )
55
60
async def query_get (request ):
56
61
query_data = request ["queries" ]
@@ -62,18 +67,22 @@ async def json(request):
62
67
print (request ["params" ]["id" ])
63
68
return jsonify ({"hello" : "world" })
64
69
70
+
65
71
@app .post ("/post" )
66
72
async def post ():
67
73
return "POST Request"
68
74
75
+
69
76
@app .post ("/post_with_body" )
70
77
async def postreq_with_body (request ):
71
78
return bytearray (request ["body" ]).decode ("utf-8" )
72
79
80
+
73
81
@app .put ("/put" )
74
82
async def put (request ):
75
83
return "PUT Request"
76
84
85
+
77
86
@app .put ("/put_with_body" )
78
87
async def putreq_with_body (request ):
79
88
print (request )
@@ -84,6 +93,7 @@ async def putreq_with_body(request):
84
93
async def delete ():
85
94
return "DELETE Request"
86
95
96
+
87
97
@app .delete ("/delete_with_body" )
88
98
async def deletereq_with_body (request ):
89
99
return bytearray (request ["body" ]).decode ("utf-8" )
@@ -93,6 +103,7 @@ async def deletereq_with_body(request):
93
103
async def patch ():
94
104
return "PATCH Request"
95
105
106
+
96
107
@app .patch ("/patch_with_body" )
97
108
async def patchreq_with_body (request ):
98
109
return bytearray (request ["body" ]).decode ("utf-8" )
@@ -107,6 +118,7 @@ async def sleeper():
107
118
@app .get ("/blocker" )
108
119
def blocker ():
109
120
import time
121
+
110
122
time .sleep (10 )
111
123
return "blocker function"
112
124
@@ -121,10 +133,14 @@ def shutdown_handler():
121
133
122
134
123
135
if __name__ == "__main__" :
124
- ROBYN_URL = os .getenv ("ROBYN_URL" , ' 0.0.0.0' )
136
+ ROBYN_URL = os .getenv ("ROBYN_URL" , " 0.0.0.0" )
125
137
app .add_header ("server" , "robyn" )
126
138
current_file_path = pathlib .Path (__file__ ).parent .resolve ()
127
139
os .path .join (current_file_path , "build" )
128
- app .add_directory (route = "/test_dir" ,directory_path = os .path .join (current_file_path , "build/" ), index_file = "index.html" )
140
+ app .add_directory (
141
+ route = "/test_dir" ,
142
+ directory_path = os .path .join (current_file_path , "build/" ),
143
+ index_file = "index.html" ,
144
+ )
129
145
app .startup_handler (startup_handler )
130
146
app .start (port = 5000 , url = ROBYN_URL )
0 commit comments