miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
598 stars 153 forks source link

Allow custom resource constructor args #181

Closed multimeric closed 3 years ago

multimeric commented 4 years ago

For example, this lets you do:

class TestResource(ResourceDetail):
    """ 
    This fake resource always renders a constructor parameter
    """ 
    def __init__(self, *args, **kwargs):
        super().__init__()
        self.constant = kwargs.get('constant')

    def get(self):
        return self.constant

api.route(TestResource, 'resource_kwargs', '/resource_kwargs', resource_kwargs={
    'constant': 'hello!'
})

Basically this is helpful if you ever want to fully customize a resource object.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.01%) to 90.786% when pulling 3de105d0dfef7e7f10384a15b8599b0968ba0e3c on TMiguelT:resource_init_args into b44bc08b11213d49fadae873650d3555889052ec on miLibris:master.