2

Adding resources and routes to a flask-restful api is pretty simple:

app = Flask(__name__)
api = restful.Api(app)

api.add_resource(MyResource,
                 'a_resource_method_endpoint/',
                  resource_class_kwargs={'param': the_param})

How can I remove MyResource and the associated endpoint from app once it's been added?

o1lo01ol1o
  • 440
  • 1
  • 5
  • 13
  • What are you trying to do? Dynamically add and remove these? – Ryan O'Donnell Dec 23 '15 at 23:24
  • Yes, dynamically adding the routes and resources is not a problem, but removing them is more difficult. I've seen the `resources` but I was hoping for a cleaner method to ensure that the correct references were removed from the correct places in the application. Updated question to specify. – o1lo01ol1o Dec 23 '15 at 23:48

1 Answers1

1

Flask-Restful adds these to an list called resources

I'd suggest you take a look at this answer here to determine the best solution for you to modify that list.

I do not believe there is a way to remove the items through an API supplied by Flask-Restful. You'll have to write a function to mutate that list based on some parameters.

I suggest iterating over the list once and removing all your routes at once: that way you save on runtime.

Community
  • 1
  • 1
Ryan O'Donnell
  • 617
  • 6
  • 14