flask-api-development
aj-geddes/useful-ai-prompts
Build RESTful APIs with Flask: routing, blueprints, SQLAlchemy ORM, JWT auth, and validation.
What is flask-api-development?
Develop lightweight Flask APIs with modular blueprints, database integration via SQLAlchemy, JWT authentication, and comprehensive request validation. Use this when building RESTful APIs, microservices, or lightweight web services that need proper structure and security.
- Create Flask applications with blueprints for modular endpoint organization
- Integrate SQLAlchemy ORM for relational database operations
- Implement JWT-based authentication and authorization
- Validate incoming requests and enforce REST principles
- Handle errors comprehensively with appropriate HTTP status codes
- Configure CORS, middleware, and environment-based settings
How to install flask-api-development
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill flask-api-development- Python 3.7+
- pip or poetry for dependency management
- Basic understanding of REST principles and HTTP
How to use flask-api-development
- 1.Install Flask and dependencies: flask, flask-sqlalchemy, flask-jwt-extended, flask-cors
- 2.Set up environment variables for DATABASE_URL and JWT_SECRET_KEY
- 3.Create an application factory function following the provided setup guide
- 4.Define SQLAlchemy models for your data entities
- 5.Create blueprints to organize related endpoints
- 6.Implement request validation using the validation patterns provided
- 7.Add JWT authentication decorators to protected routes
- 8.Test endpoints with curl or a REST client
Use cases
- Building a RESTful API for a mobile or web application
- Creating microservices with minimal overhead and fast startup
- Implementing a lightweight authentication system for internal tools
- Designing paginated collection endpoints with proper filtering
- Integrating with PostgreSQL or SQLite databases in a structured way
- Backend developers building APIs with Python
- Teams creating microservices architectures
- Developers migrating from other frameworks to Flask
- Engineers building lightweight authentication systems
flask-api-development FAQ
No, but it's recommended for relational databases. You can use raw SQL or other ORMs, but SQLAlchemy integrates well with Flask and handles common patterns.
Use Flask-Migrate (built on Alembic) to manage schema changes. Initialize with `flask db init`, create migrations with `flask db migrate`, and apply with `flask db upgrade`.
This skill focuses on REST APIs. For GraphQL, you'd use Flask-GraphQL or similar extensions alongside these patterns.
Common options include Gunicorn + Nginx, Docker containers, AWS Lambda, or PaaS platforms like Heroku. Use environment variables for configuration across environments.
App factory creates the Flask app instance with configuration; blueprints organize routes into reusable modules. Use both together for scalable APIs.
Full instructions (SKILL.md)
Source of truth, from aj-geddes/useful-ai-prompts.
name: flask-api-development description: > Develop lightweight Flask APIs with routing, blueprints, database integration, authentication, and request/response handling. Use when building RESTful APIs, microservices, or lightweight web services with Flask.
Flask API Development
Table of Contents
Overview
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
Related skills
More from aj-geddes/useful-ai-prompts and the wider catalog.

flutter-development
>

Funnel Analysis
Analyze user conversion funnels, identify drop-off points, and optimize conversion rates for conversion optimization and user flow analysis

ios-swift-development
Develop native iOS apps with Swift, SwiftUI, MVVM, and modern async patterns.

jenkins-pipeline
Build enterprise Jenkins pipelines with declarative and scripted syntax for CI/CD automation.

kubernetes-deployment
>

markdown-documentation
Master markdown formatting and GitHub Flavored Markdown for professional documentation.