Ho do you configure the app to have following features:
Have an api-endpoint defined as app.add_route('/v1/tablets', TabletsCollection())
And still be able to use QueryParams like this https://example.com/api/v1/tablets?limit=12&offset=50&q=tablet name
the Collection has two methods on_get
for retrieving the whole list and using the filter and on_post
for the creation of a single record.
I've been searching the net for some time, how do you get query_string and properly parsed params?
Both the query string and the parsed query string (as a dict) are available on the Request object that falcon passes to your API endpoint.
Your handler can do stuff like:
class TabletsCollection():
def on_post(self, req, resp):
print req.query_string
for key, value in req.params.items():
print key, value
See http://falcon.readthedocs.io/en/stable/api/request_and_response.html#Request.query_string and http://falcon.readthedocs.io/en/stable/api/request_and_response.html#Request.params.
You can use falcon.uri module to parse query string.
qs = falcon.uri.parse_query_string(req.query_string)
if "myq" in qs:
searchedQ = qs["myq"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With