Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
First Endpoint, Flask-Migration and SQLite Studio | Endpoints with Blueprints and MethodView
Professional Web API with Flask
course content

Contenido del Curso

Professional Web API with Flask

Professional Web API with Flask

1. Introduction to the Course
2. Database and Models
3. Flask-Smorest and Schemas
4. Endpoints with Blueprints and MethodView
5. Authentication with JWT
6. Deployment

book
First Endpoint, Flask-Migration and SQLite Studio

Implementing the Club Endpoint

Let's define our first functionality for the Club GET endpoint. We return a ClubModel.query.get_or_404() using ORM, passing the club_id. This simplifies the development process by avoiding raw SQL queries. We import our model from the respective module.

Combining Methods and Schemas

We also need to link our method to the schema we created for data serialization and validation. We use the @blp.response() decorator to return a 200 status code for successful request processing and import ClubSchema from our schemas module.

Migrations

From our previous project, we're familiar with migrations and the Flask-Migrate library. We install Flask-Migrate using:

Initializing Migrations and Database Connection

We need to initialize migrations and link our application to the database. In the app.py file, we import Migrate from the flask_migrate library.

At the end of our file, we initialize a new migrate variable to connect our application (app) and the database (db).

Creating Migration Folders

We're ready to create a folder for our future migrations using the flask db init command. A new folder named migrations appears, containing several files and a versions subfolder.

Using SQLite Studio

Please follow the video to quickly and practically learn how to use the SQLite Studio app.

In the next chapters, we'll explore additional documentation features and testing capabilities for our API and continue defining functionalities for all models.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 3
We're sorry to hear that something went wrong. What happened?
some-alt