Getting Started – Running the Application
This section walks you through starting the Flask development server for the Library REST API. Ensure you have cloned the repository, activated your Python 3.8 virtual environment, and installed all dependencies before proceeding.
1. Activate Your Virtual Environment
Make sure your virtual environment is active in the directory containing app.py:
# macOS / Linux
source venv/bin/activate
# Windows (PowerShell)
venv\Scripts\Activate.ps1
2. Launch the Server
From the same directory, run:
python app.py
This command:
- Imports your Flask app and initializes extensions
- Configures the database and JWT
- Registers all REST resources
- Starts the server on port 5000 in debug mode
3. Configuration Overview
| Configuration Key | Purpose |
|---|---|
| SQLALCHEMY_DATABASE_URI | Points to the SQLite file data.db. |
| SQLALCHEMY_TRACK_MODIFICATIONS | Enables event notifications (set to True by default). |
| PROPAGATE_EXCEPTIONS | Forces Flask to bubble up exceptions for debugging. |
| secret_key | Used by Flask-JWT to sign and verify JWT tokens. |
All settings live in app.config at the top of app.py .
4. Initialization Flow
flowchart TD
A[Run python app.py] --> B[db.init_app app]
B --> C[before_first_request creates tables]
C --> D[JWT app authenticate identity]
D --> E[api.add_resource registrations]
E --> F[app.run port 5000 debug True]
db.init_app(app)- Binds the SQLAlchemy instance from
db.pyto your Flask app. @app.before_first_request- Calls
create_tables()once to rundb.create_all(), creatingusers,stores, andbookstables indata.db. JWT(app, authenticate, identity)- Sets up the
/authendpoint for user login and token issuance. api.add_resource(...)- Registers five resources:
Store→/store/<name>StoreList→/storesBook→/book/<title>BookList→/booksUserRegister→/registerapp.run(port=5000, debug=True)- Starts the development server on http://localhost:5000 with debug mode enabled.
5. Important Notes
{
"title": "Development Mode",
"content": "The server runs with debug=True. Disable this in production to avoid exposing sensitive information."
}
{
"title": "Database File",
"content": "A local SQLite file named data.db is created on first run. Back it up before schema changes."
}
Once the server is running, you can explore all endpoints (books, stores, authentication, and user registration) using the provided Postman collection or your tool of choice.