# Basic Flask initialization
app = Flask(__name__)
app.config.from_object(config) # Set the configuration variables to the flask application
cache = Cache(app) # Initialize Cache
api = Api(app)
# Adding a base url.
api.add_resource(Index,"/")
api.add_resource(News,"/news","/news/<string:ticker>")
This is what my main function looks like, I'm using python package structure to access the main function using a console script. The config is simple. I'm using redis inside a docker to cache, but how do I implement it with Flask Restful more particularly if my class looks like this.
class News(Resource):
@cache.cached(timeout=30, query_string=True)
def get(self, ticker=None) -> dict:
# Default Response when no ticker input in specified.
if not ticker:
return {"Response":"200","Message":"API supports all ticker inputs, invalid ones will return no data whatsoever."}
# Response when ticker exists
if ticker:
# Supplying ticker supplied to the crawler function.
data = crawler_func(ticker)
# Returning provided input and data response.
return {
"ticker":ticker,
"headlines":data,
}