I'm try to do a RESTFul Api with tornado framework but i don't have idea how handler the url routes for the handlers, I try to do something like this Tornado Restful Handler Classes this cuestion is 3 years ago and i ask if now exists a better way for do that. Now exist a elegant way for handler the url routes of RESTFul API?
Asked
Active
Viewed 1,841 times
0
-
its already so elegant. Tornado already is doing a lot of work, what else do we need. – shadab.tughlaq Dec 25 '14 at 07:06
1 Answers
3
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
self.write("Hello, world")
def post(self, *args, **kwargs):
self.write("Hello, world")
class IDHandler(tornado.web.RequestHandler):
def post(self, *args, **kwargs):
_id = args[0]
self.write(_id)
application = tornado.web.Application([
(r"/", MainHandler),
(r"/(\d+)$", IDHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
if your request http://127.0.0.1:8888/
in get
or post
method your give 'Hello, world'
if you request http://127.0.0.1:8888/12
in post
method your give '12'

Zaaferani
- 951
- 9
- 31