Search code examples
python-3.xflask-restfulflask-restplus

How to get resource path in flask-RESTPlus?


I am fairly new at working with flask and flask-RESTPlus. I have the following and it is not clear how can I determine which path was used in the get request?

ns = api.namespace('sample', description='get stuff')

@ns.route(
    '/resource-settings/<string:address>',
    '/unit-settings/<string:address>',
    '/resource-proposals/<string:address>',
    '/unit-proposals/<string:address>')
@ns.param('address', 'The address to decode')
class Decode(Resource):
    @ns.doc(id='Get the decoded result of a block address')
    def get(self, address):
        # How do I know what get path was called?
        pass

Solution

  • A better solution would be to use the request context. To get the full path, you can do:

    from flask import request
    
    def get(self, address):
        # How do I know what get path was called?
        print(request.full_path)