I’m trying to implement some sort of API on tornado and I have such question:
is it possible to route two urls to one handler separating by method.
class Handler():
def get(self):
#only for the first url
def post(self):
#only for the secornd url
handlers = [
(r"/url1",Handler), #only GET are allowed
(r"/url2",Handler), #only POST are allowed
]
So if someone trying to send POST to the first url he should see error message
One way to achieve what you want to do is to use regex in your url and check for the attribute in your methods handler.
Example of urls to map
And an example of the corresponding handler
I would map ‘my_param’ options to a dictionary to keep things clear and to avoid me to dive into the handler if I need to change these values or if I want to add new urls.