restless
restless copied to clipboard
Add request parameter access
I'd like to suggest adding Request.request_parameters
and Resource.params
, which follows the idea of Resource.data
. This would allow you to easily create endpoints that have e.g. optional filtering.
Example usage (untested):
data = ["one", "two", "three"]
class MyResource(Resource):
def detail(self, pk):
return data[int(pk)]
def list(self):
if "slice" in self.params:
return data[slice(*map(int, self.params["slice"]))]
return data
Which would allow GET /resource/?slice=1,3
to return data[1, 3]
(["two", "three"]
).
If this gets approved, I'll update the docs and test suite