Skip to content

Commit f99817f

Browse files
committed
Added tornado http server
1 parent 329dc1f commit f99817f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ pydantic==1.6.1
77
uvicorn==0.11.3
88
pyramid==1.10.4
99
waitress==1.4.4
10-
bottle==0.12.18
10+
bottle==0.12.18
11+
tornado==6.0.4

src/servers/http/tornado_server.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
3+
import json
4+
from tornado.web import Application, RequestHandler
5+
from tornado.ioloop import IOLoop
6+
from src.servers.config import host, port
7+
8+
class HelloHandler(RequestHandler):
9+
def post(self):
10+
data = json.loads(self.request.body)
11+
self.set_header('Content-Type', 'application/json')
12+
self.write(json.dumps({ 'hello': data['name'] }))
13+
14+
def make_app():
15+
urls = [('/hello', HelloHandler)]
16+
return Application(urls, debug=True)
17+
18+
def run_test():
19+
print('Server starting at ' + 'http://{}:{}'.format(host, port))
20+
21+
app = make_app()
22+
app.listen(port, host)
23+
IOLoop.current().start()
24+
25+
if __name__ == '__main__':
26+
run_test()

0 commit comments

Comments
 (0)