inveniosoftware / flask-resources

REST APIs for Flask
https://flask-resources.readthedocs.io
MIT License
3 stars 21 forks source link

Uniformly Implement URL query string parsing for all endpoints #59

Closed fenekku closed 4 years ago

fenekku commented 4 years ago

(may be related to #40)

URL query string parsing is done inside the Item/List/SingletonView methods which means there is repetition and inconsistencies (not being done on certain endpoints). There is no telling what endpoints the developer making use of this library might want to have query string parsing on, so we should allow for all. We also want query strings parsing to be part of the config. This is what we are going for:

class MyResourceConfig(ResourceConfig):
    """Resource configuration."""

    request_querystring = ArgsParser({
            "page": Int(validate=Range(min=1), missing=1),
            "from": Int(validate=Range(min=1)),
            "size": Int(validate=Range(min=1), missing=10),
            "q": String(missing=""),
        }
    )
    # or
    request_querystring = {
        "search": ArgsParser({
            "page": Int(validate=Range(min=1), missing=1),
            "from": Int(validate=Range(min=1)),
            "size": Int(validate=Range(min=1), missing=10),
            "q": String(missing=""),
        })
    }