Create efficient Flask APIs with blueprints for modular organization, SQLAlchemy for ORM, JWT authentication, comprehensive error handling, and proper request validation following REST principles.
When to Use
Building RESTful APIs with Flask
Creating microservices with minimal overhead
Implementing lightweight authentication systems
Designing API endpoints with proper validation
Integrating with relational databases
Building request/response handling systems
Quick Start
Minimal working example:
# app.py
from flask import Flask, request, jsonify
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
from flask_jwt_extended import JWTManager
import os
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'sqlite:///app.db')
app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY', 'dev-secret')
app.config['JSON_SORT_KEYS'] = False
db = SQLAlchemy(app)
jwt = JWTManager(app)
CORS(app)
# Request ID middleware
@app.before_request
def assign_request_id():
import uuid
request.request_id = str(uuid.uuid4())
# Error handlers
@app.errorhandler(400)
def bad_request(error):
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
Guide
Contents
Flask Application Setup
Flask Application Setup
Database Models with SQLAlchemy
Database Models with SQLAlchemy
Authentication and JWT
Authentication and JWT
Blueprints for Modular API Design
Blueprints for Modular API Design
Request Validation
Request Validation
Application Factory and Configuration
Application Factory and Configuration
Best Practices
✅ DO
Use blueprints for modular organization
Implement proper authentication with JWT
Validate all user input
Use SQLAlchemy ORM for database operations
Implement comprehensive error handling
Use pagination for collection endpoints
Log errors and important events
Return appropriate HTTP status codes
Implement CORS properly
Use environment variables for configuration
❌ DON'T
Store secrets in code
Use global variables for shared state
Ignore database transactions
Trust user input without validation
Return stack traces in production
Use mutable default arguments
Forget to handle database connection errors
Implement authentication in route handlers
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: aj-geddes-useful-ai-prompts-flask-api-development3description: Flask API Development4---56# Flask API Development78## Table of Contents910- [Overview](#overview)11- [When to Use](#when-to-use)12- [Quick Start](#quick-start)13- [Reference Guides](#reference-guides)14- [Best Practices](#best-practices)1516## Overview1718Create efficient Flask APIs with blueprints for modular organization, SQLAlchemy for ORM, JWT authentication, comprehensive error handling, and proper request validation following REST principles.1920## When to Use2122- Building RESTful APIs with Flask23- Creating microservices with minimal overhead24- Implementing lightweight authentication systems25- Designing API endpoints with proper validation26- Integrating with relational databases27- Building request/response handling systems2829## Quick Start3031Minimal working example:3233```python34# app.py35from flask import Flask, request, jsonify36from flask_cors import CORS37from flask_sqlalchemy import SQLAlchemy38from flask_jwt_extended import JWTManager39import os4041app = Flask(__name__)42app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'sqlite:///app.db')43app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY', 'dev-secret')44app.config['JSON_SORT_KEYS'] = False4546db = SQLAlchemy(app)47jwt = JWTManager(app)48CORS(app)4950# Request ID middleware51@app.before_request52def assign_request_id():53 import uuid54 request.request_id = str(uuid.uuid4())5556# Error handlers57@app.errorhandler(400)58def bad_request(error):59// ... (see reference guides for full implementation)60```6162## Reference Guides6364Detailed implementations in the `references/` directory:6566| Guide | Contents |67|---|---|68| [Flask Application Setup](references/flask-application-setup.md) | Flask Application Setup |69| [Database Models with SQLAlchemy](references/database-models-with-sqlalchemy.md) | Database Models with SQLAlchemy |70| [Authentication and JWT](references/authentication-and-jwt.md) | Authentication and JWT |71| [Blueprints for Modular API Design](references/blueprints-for-modular-api-design.md) | Blueprints for Modular API Design |72| [Request Validation](references/request-validation.md) | Request Validation |73| [Application Factory and Configuration](references/application-factory-and-configuration.md) | Application Factory and Configuration |7475## Best Practices7677### ✅ DO7879- Use blueprints for modular organization80- Implement proper authentication with JWT81- Validate all user input82- Use SQLAlchemy ORM for database operations83- Implement comprehensive error handling84- Use pagination for collection endpoints85- Log errors and important events86- Return appropriate HTTP status codes87- Implement CORS properly88- Use environment variables for configuration8990### ❌ DON'T9192- Store secrets in code93- Use global variables for shared state94- Ignore database transactions95- Trust user input without validation96- Return stack traces in production97- Use mutable default arguments98- Forget to handle database connection errors99- Implement authentication in route handlers100101---102> Converted and distributed by [TomeVault](https://tomevault.io/claim/aj-geddes) — claim your Tome and manage your conversions.103<!-- tomevault:4.0:skill_md:2026-04-11 -->
Run npx skillmds@latest add tomevault-io/aj-geddes-useful-ai-prompts-flask-api-development in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Flask API Development It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.