-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_api.py
More file actions
35 lines (25 loc) · 841 Bytes
/
server_api.py
File metadata and controls
35 lines (25 loc) · 841 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
import cherrypy as http
import cherrypy
from contextlib import contextmanager
class RestApi:
def __init__(self, msg_post="[TypeFizz, TypeBUzz, TypeNone, TypeFizzBuzz]") -> None:
self.msg_post = msg_post
@http.expose
def index(self):
return "<html><body><p>{0}</p></body></html>".format(self.msg_post)
@contextmanager
def test_run_server():
cherrypy.config.update({'server.socket_port': 8181})
cherrypy.engine.start()
cherrypy.engine.wait(cherrypy.engine.states.STARTED)
yield
cherrypy.engine.exit()
cherrypy.engine.block()
def run_server(msg=None):
http.config.update( {'server.socket_host':"0.0.0.0", 'server.socket_port':8181 } )
if msg:
http.quickstart( RestApi(msg) )
else:
http.quickstart( RestApi() )
if __name__ == '__main__':
run_server()