restless icon indicating copy to clipboard operation
restless copied to clipboard

Add request parameter access

Open madsmtm opened this issue 5 years ago • 0 comments

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

madsmtm avatar Nov 23 '18 10:11 madsmtm