Is it safe to nest the route decorator?

24 views
Skip to first unread message

Keith Hanlan

unread,
Jan 9, 2018, 6:24:11 PM1/9/18
to bottlepy
We are renaming one of our bottle endpoints but need to retain the original name for backwards compatability.

We have found that the following construct works perfectly well but I would like to know if it is safe or if there is a preferred approach:
@service.route("/getdumpdata", method='POST') # New endpoint - to be deprecated eventually
@service.route("/getmeta", method='POST')     # Original endpoint
@serialize
@except_errors
def dump_data():
   
...
   
return api.get_dump_data(...)

Thank you for your help.
Keith

Marcel Hellkamp

unread,
Jan 10, 2018, 5:02:44 AM1/10/18
to bott...@googlegroups.com
Hi Keith

yes, this is safe. The decorator just registers the handler function and does not actually decorate (wrap) it, so chaining is allowed. Just remember that the order is significant. Since decorators are applied in reverse order, '/getmeta' will have precedence over '/getdumpdata' in your example, which is fine since both routes are unambiguous anyway. Just be careful with ambiguous (overlapping) routes.

mfg, Marcel

Reply all
Reply to author
Forward
0 new messages