Closed kgriffs closed 7 months ago
This is EXACTLY what I'm after.
I'm basically making my own server that wraps an external API, but does some processing on some of the functions, and is accessed by ajax so need to avoid CORS and my own caching.
I've added a route decorator and basically do this.
@route('/market/{instrument}/{currency}/trades?since={timestamp}')
class Trades(RoutedHandler):
def __init__(self):
super().__init__()
Of course the 'timestamp' param in the above example does not get passed as **kwargs, but for all simple "/" param based API calls, it's saved me a LOT of time and effort, and is quite elegant.
Then in the super I do
def on_get(self, req, resp, **kwargs):
url = config.domain + self.get_route(**kwargs)
if req.params:
url += "?{}".format(req.query_string)
result = requests.get(url)
resp.body = result.text
I wish I knew how to work around this, but I've only been using Falcon since yesterday. 👍 and it would be nice if the querystring arguments could be used for routing.
Given this has generated only a limited interest from the community, I think we want to keep the default router focused solely on routing based on req.path
. However, I filed a separate issue to be able to easier extend the default router with additions like this one: #2219.
We can borrow from RFC 6570 syntax and do something like this:
Note that all params would default to None if present. I'm assuming we would just pass these as kwargs to the responder method.
Filters could be specified by extending RFC 6570, i.e: