diff --git a/restless/fl.py b/restless/fl.py index ea34c06..861dba7 100644 --- a/restless/fl.py +++ b/restless/fl.py @@ -41,6 +41,9 @@ def _wrapper(*args, **kwargs): def request_body(self): return self.request.data + def request_parameters(self): + return self.request.args + def is_debug(self): from flask import current_app return current_app.debug diff --git a/restless/resources.py b/restless/resources.py index 644319d..41198a2 100644 --- a/restless/resources.py +++ b/restless/resources.py @@ -77,6 +77,7 @@ def __init__(self, *args, **kwargs): self.init_args = args self.init_kwargs = kwargs self.request = None + self.params = None self.data = None self.endpoint = None self.status = 200 @@ -171,6 +172,21 @@ def request_body(self): # By default, Django-esque. return self.request.body + def request_parameters(self): + """ + Returns the current request URL parameters. + + Useful for providing custom options on your resources. + + If you're integrating with a new web framework, you might need to + override this method within your subclass. + + :returns: The request parameters, parsed as a mapping + :rtype: dict + """ + # By default, Django-esque. + return self.request.GET + def build_response(self, data, status=200): """ Given some data, generates an HTTP response. @@ -281,6 +297,7 @@ def handle(self, endpoint, *args, **kwargs): if not self.is_authenticated(): raise Unauthorized() + self.params = self.request_parameters() self.data = self.deserialize(method, endpoint, self.request_body()) view_method = getattr(self, self.http_methods[endpoint][method]) data = view_method(*args, **kwargs) diff --git a/restless/tnd.py b/restless/tnd.py index 8231d39..2bd729a 100644 --- a/restless/tnd.py +++ b/restless/tnd.py @@ -128,6 +128,9 @@ def request_method(self): def request_body(self): return self.request.body + def request_parameters(self): + return self.request.query_arguments + def build_response(self, data, status=OK): if status == NO_CONTENT: # Avoid crashing the client when it tries to parse nonexisting JSON.