inveniosoftware / flask-resources

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

Thoughts on refactor #94

Open fenekku opened 3 years ago

fenekku commented 3 years ago

Overall the refactor is quite good. Here is my list of notes / potential areas for improvements / fixes. They are mostly from the perspective of a developer using the library:

    @request_parser(
        {'q': ma.fields.String(required=True)},
        # Other locations include args, view_args, headers.
        location='args',
    )
    @response_handler(many=True)
    def search(self):
        # The validated data is available in the resource request context.
        if resource_requestctx.args['q']:
            # ...
        # From the view you can return an object which the response handler
        # will serialize.
        return [], 200

    # You can parse request body depending on the Content-Type header.
    @request_parser(
        {"application/json": RequestBodyParser(JSONDeserializer())}
        location='body'    
    )

This is really for developer convenience: less bits to import and simpler semantics. Behind the scene we do the work of wiring thins together nicely.