spring-like request_mapping for tornado.
Project description
install
pip install -U git+https://github.com/sazima/tornado_request_mapping
A simple example
import tornado.ioloop
from tornado.websocket import WebSocketHandler
import tornado.web
from tornado_request_mapping import request_mapping, Route
@request_mapping("/test")
class MainHandler(tornado.web.RequestHandler):
@request_mapping('/get_by_id', method='get')
async def test(self):
self.write("Hello, world. get")
@request_mapping('/update_by_id', method='post')
async def test1(self):
self.write("Hello, world. post")
@request_mapping('/t')
class MyHandler(tornado.web.RequestHandler):
@request_mapping('/get_by_id', method='put')
async def test(self):
self.write("Hello, world. put")
@request_mapping("/ws")
class Wshandler(WebSocketHandler):
def open(self, *args: str, **kwargs: str):
print('open')
def close(self, code: int = None, reason: str = None) -> None:
print('close')
def check_origin(self, origin: str) -> bool:
return True
if __name__ == "__main__":
app = tornado.web.Application()
route = Route(app)
route.register(MainHandler)
route.register(MyHandler)
route.register(Wshandler)
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file tornado_request_mapping-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: tornado_request_mapping-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.6.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10ea8f14f6f8a8d01b57b5c7ab7d88ce4998eff7fcf67fc0d63d56b2ceec2c3b |
|
MD5 | b4cc23fbeb2a4f75b51f85af8ec3e3b4 |
|
BLAKE2b-256 | 9d8cbeec79231ff98bf6557ac25f114df9e87faedd3f0dfa6bd4bdc11a622559 |