tamizhselvam
2015-09-05 03:57:42 UTC
Hi, I've recently started learning and working with Bottle after a few
months of JavaScript web development, mainly using ExpressJS. A feature of
that framework I used often was defining a callback to be executed when the
requested route contained a certain parameter. For instance, if the
parameter to be matched was 'id', then the callback would get the model
instance corresponding to the id value and set it as an attribute on the
request object. For routes that made use of this parameter, such as those
for read, update, and delete methods for a resource, the model instance to
be returned or modified would be immediately available in the controller
method. I'd like to know if it would be possible for me to implement
something similar in Bottle. Based on my limited experience with Bottle,
here are a couple of ways I thought I might be able to make this work:
1. Create a separate app for each RESTful resource. Attach a callback to
the 'before_request' hook for an app that checks the request route for the
parameter and then gets and sets the corresponding model instance on the
request object.
2. Define a decorator that does the check and modification of the request
object, and apply it on all the callbacks for routes containing the
parameter.
Neither of these ways seems ideal to me. I would prefer to just have a
single 'api' app which contains the routes and controllers for all of the
RESTful resources. The second way involves some redundancy in having to
repeat the decorator for each route containing the parameter. I would
appreciate your thoughts and suggestions on other ways of implementing the
feature described above in Bottle.
Thanks.
--
months of JavaScript web development, mainly using ExpressJS. A feature of
that framework I used often was defining a callback to be executed when the
requested route contained a certain parameter. For instance, if the
parameter to be matched was 'id', then the callback would get the model
instance corresponding to the id value and set it as an attribute on the
request object. For routes that made use of this parameter, such as those
for read, update, and delete methods for a resource, the model instance to
be returned or modified would be immediately available in the controller
method. I'd like to know if it would be possible for me to implement
something similar in Bottle. Based on my limited experience with Bottle,
here are a couple of ways I thought I might be able to make this work:
1. Create a separate app for each RESTful resource. Attach a callback to
the 'before_request' hook for an app that checks the request route for the
parameter and then gets and sets the corresponding model instance on the
request object.
2. Define a decorator that does the check and modification of the request
object, and apply it on all the callbacks for routes containing the
parameter.
Neither of these ways seems ideal to me. I would prefer to just have a
single 'api' app which contains the routes and controllers for all of the
RESTful resources. The second way involves some redundancy in having to
repeat the decorator for each route containing the parameter. I would
appreciate your thoughts and suggestions on other ways of implementing the
feature described above in Bottle.
Thanks.
--
--
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.
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.