Discussion:
[bottlepy] Is it safe to nest the route decorator?
Keith Hanlan
2018-01-09 21:25:21 UTC
Permalink
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
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Marcel Hellkamp
2018-01-10 10:02:41 UTC
Permalink
Post by Keith Hanlan
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
|
@service.route("/getdumpdata",method='POST')# New endpoint - to be
deprecated eventually
@service.route("/getmeta",method='POST')    # Original endpoint
@serialize
@except_errors
    ...
    returnapi.get_dump_data(...)
|
Thank you for your help.
Keith
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
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...