Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

make routing similar to flask blueprint

Project description

  • Just like flask blueprint, Handler match to url prefix and the url endpoint map to handler instance method decorated by route decorator.

INSTALL

pip install tor-router (recommended pypi: "https://pypi.python.org/pypi")

EXAMPLE

from tornado import gen
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from web import TrfRequestHandler, route, TrfApplication


class TrfHandler(TrfRequestHandler):
    def get(self, *args, **kwargs):
        self.write("get ok")
        self.finish()

    @gen.coroutine
    def post(self, *args, **kwargs):
        self.write("post ok")
        self.finish()

    @route("/hello")
    def say_hello(self, *args, **kwargs):
        self.write("hello")
        self.finish()

    @route("/hi")
    @gen.coroutine
    def say_hi(self, *args, **kwargs):
        self.write("hi")
        self.finish()

    @route("/fine", allow_method=["get", "post", "put"])
    @gen.coroutine
    def say_fine(self, *args, **kwargs):
        self.write("fine")
        self.finish()


if __name__ == '__main__':
    app = TrfApplication([(r"/api", TrfHandler)])
    server = HTTPServer(app)
    print 8988
    server.listen(8988)
    IOLoop.current().start()

Requirement

  • Cpython 2.7.12
  • tornado 4.2.1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tor-router, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size tor_router-0.0.3-py2-none-any.whl (8.2 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size tor_router-0.0.3.tar.gz (6.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page