Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSamson Chapuramhuka
7,390 PointsCreate a new variable named api in each of the resources that's an Api instance for the Blueprint. Then add both of the
Create a new variable named api in each of the resources that's an Api instance for the Blueprint. Then add both of the Resources to api. You can use whatever endpoint name you want, but make sure the URL pattern is like "/api/v1/[PLURAL RESOURCE]". Remember to include the id argument in the appropriate URLs.
from flask import Flask
from resource.ingredients import ingredients_api
from resource.recipes import recipes_api
app = Flask(__name__)
app.register_blueprint(recipes_api)
app.register_blueprint(ingredients_api)
if __name__ == '__main__':
app.run()
api.add_ingredients(
IngredientsList,
'/api/v1/ingredients',
endpoint='ingredients'
)
api.add_resource(
Ingredients,
'/api/v1/ingredients/<int:id>',
endpoint='ingredient'
)
api.add_resource(
RecipeList,
'/api/v1/recipes',
endpoint='recipes'
)
api.add_resource(
Recipe,
'/api/v1/recipes/<int:id>',
endpoint='recipe'
)