import tornado.ioloop
import pyrestful.rest
from pyrestful import mediatypes
from pyrestful.rest import get
class EchoService(pyrestful.rest.RestHandler):
# 定义路由 和 返回值类型JSON
@get(_path="/echo/{name}", _produces=mediatypes.APPLICATION_JSON)
def sayHello(self, name):
return {"Hello": name}
if __name__ == '__main__':
try:
print("Start the echo service")
# 载入输出类
app = pyrestful.rest.RestService([EchoService])
# 监听接口
app.listen(8080)
# io池启动
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print("\nStop the echo service")
tronado restful
最新推荐文章于 2021-09-12 12:40:12 发布