I am looking to pass an object instance as a parameter into a Flask-RESTfull Resource.
Here is my setup:
# in main.py
from flask import Flask
from flask.ext.restful import Api
from bar import Bar
from foo import views
app = Flask(__name__)
api = Api(app)
my_bar = Bar()
api.add_resource(views.ApiPage, "/api/my/end/point/")
Then in views.py I have the resource set up as follows:
# In views.py
from flask.ext.restful import Resource
class ApiPage(Resource):
def get(self):
serialized = str(my_bar)
return serialized
So the issue that I am having is that I need to pass my instance of Bar()
into the api resource. Is there any way to pass it in through the add_resource
method like api.add_resource(views.ApiPage, "/api/my/end/point/", instance=bar)
?