Skip to content

Conversation

madsmtm
Copy link

@madsmtm madsmtm commented Nov 23, 2018

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

return self.request.body

def request_parameters(self):
return self.request.query_arguments
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is incomplete, HTTPServerRequest.query_arguments returns a mapping that points to bytes, not str. I'm not sure how to cleanly fix this, we could maybe use RequestHandler.decode_argument, but this would cause us to automatically parse the arguments before somebody actually needs them. Another option is to add a helper class around RequestHandler.get_query_argument with __getitem__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant