PluginBench
Skill
Review
Audit score 70

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
Prerequisites
  • Python 3.7+
  • pip or poetry for dependency management
  • Basic understanding of REST principles and HTTP
Claude Code
Cursor
Windsurf
Cline

How to use flask-api-development

  1. 1.Install Flask and dependencies: flask, flask-sqlalchemy, flask-jwt-extended, flask-cors
  2. 2.Set up environment variables for DATABASE_URL and JWT_SECRET_KEY
  3. 3.Create an application factory function following the provided setup guide
  4. 4.Define SQLAlchemy models for your data entities
  5. 5.Create blueprints to organize related endpoints
  6. 6.Implement request validation using the validation patterns provided
  7. 7.Add JWT authentication decorators to protected routes
  8. 8.Test endpoints with curl or a REST client

Use cases

Good for
  • 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
Who it's for
  • 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

Do I need to use SQLAlchemy?

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.

How do I handle database migrations?

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`.

Can I use this for GraphQL APIs?

This skill focuses on REST APIs. For GraphQL, you'd use Flask-GraphQL or similar extensions alongside these patterns.

How do I deploy a Flask API?

Common options include Gunicorn + Nginx, Docker containers, AWS Lambda, or PaaS platforms like Heroku. Use environment variables for configuration across environments.

What's the difference between blueprints and app factory?

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:

GuideContents
Flask Application SetupFlask Application Setup
Database Models with SQLAlchemyDatabase Models with SQLAlchemy
Authentication and JWTAuthentication and JWT
Blueprints for Modular API DesignBlueprints for Modular API Design
Request ValidationRequest Validation
Application Factory and ConfigurationApplication 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