Community编程与开发github.com

aj-geddes/flask-api-development

使用路由、蓝图、数据库集成、认证和请求/响应处理开发轻量级 Flask API。适用于构建 RESTful API、微服务或使用 Flask 的轻量级 Web 服务。

flask-api-development 是什么?

该技能专注于使用 Flask 框架开发高效、轻量级的 API,提供从路由、蓝图设计到数据库集成、用户认证和请求/响应处理的完整支持。它特别适合构建 RESTful API、微服务或轻量级 Web 服务,帮助开发者快速实现可扩展的后端。技能覆盖了诸如 SQLAlchemy 的数据库交互、JWT 或 OAuth 认证机制,以及结构化蓝图用于模块化开发。基于 SKILL.md 文档,它倡导遵循 Flask 最佳实践,确保代码简洁、可维护。用户可以通过该技能自动生成样板代码、配置文件和示例,从而加速原型的搭建,减少重复劳动。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/aj-geddes/useful-ai-prompts/tree/main/skills/flask-api-development

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

flask-api-development 是做什么的?

使用路由、蓝图、数据库集成、认证和请求/响应处理开发轻量级 Flask API。适用于构建 RESTful API、微服务或使用 Flask 的轻量级 Web 服务。

概述

aj-geddes/flask-api-development 专为使用 Flask 框架创建高效、可维护的 API 而设计。它简化了常见模式,如路由组织、数据库操作和认证集成,帮助开发者专注于业务逻辑。

主要特性

  • 路由和蓝图:通过结构化的蓝图模块化 API 端点。
  • 数据库集成:使用 SQLAlchemy 或其他 ORM 进行数据库交互。
  • 认证:内置对 JWT 和 OAuth 等主流认证机制的支持。
  • 请求/响应处理:解析请求数据、验证输入并规范化响应。
  • 错误处理:集中化错误处理模式,提供有意义的 HTTP 状态码和消息。

使用场景

  • 构建 RESTful API 后端。
  • 创建微服务架构中的独立服务。
  • 开发需要快速迭代的轻量级 Web 服务。

快速开始

  1. 安装依赖:

    pip install flask flask-sqlalchemy flask-jwt-extended
    
  2. 创建主应用文件 app.py:

    from flask import Flask
    from flask_sqlalchemy import SQLAlchemy
    
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
    db = SQLAlchemy(app)
    
    @app.route('/')
    def home():
        return {'message': 'Hello, World!'}
    
  3. 运行应用:

    flask run
    

最佳实践

  • 使用蓝图将路由按功能模块化,例如 auth.py、users.py 等。
  • 在环境变量或配置文件中管理敏感信息(如密钥)。
  • 使用异常处理中间件统一错误响应。
  • 为数据库模型定义清晰的模式(schema)。

示例蓝图结构

myapp/
├── app.py
├── config.py
├── models/
│   └── user.py
├── routes/
│   ├── auth.py
│   └── users.py
└── utils/
    └── helpers.py

认证示例

使用 Flask-JWT-Extended 添加 JWT 认证:

from flask_jwt_extended import JWTManager, create_access_token

app.config['JWT_SECRET_KEY'] = 'super-secret'
jwt = JWTManager(app)

@app.route('/login', methods=['POST'])
def login():
    token = create_access_token(identity='user')
    return {'token': token}

数据库集成

配置 SQLAlchemy 并定义模型:

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy(app)

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)

贡献

欢迎贡献!请 fork 仓库并提交 pull request。

许可

MIT

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

aj-geddes/android-kotlin-development

Develop native Android apps with Kotlin. Covers MVVM with Jetpack, Compose for modern UI, Retrofit for API calls, Room for local storage, and navigation architecture.

aj-geddes/ansible-automation

Infrastructure automation and configuration management using Ansible playbooks, roles, and inventory. Use for deploying applications, patching, and managing servers.

aj-geddes/architecture-diagrams

Create system architecture diagrams using Mermaid, PlantUML, C4 model, flowcharts, and sequence diagrams. Use when documenting architecture, system design, data flows, or technical workflows.

aj-geddes/code-review-analysis

Perform comprehensive code reviews with best practices, security checks, and constructive feedback. Use when reviewing pull requests, analyzing code quality, checking for security vulnerabilities, or providing code improvement suggestions.

aj-geddes/ios-swift-development

Develop native iOS apps with Swift. Covers MVVM architecture, SwiftUI, URLSession for networking, Combine for reactive programming, and Core Data persistence.

aj-geddes/jenkins-pipeline

Build Jenkins declarative and scripted pipelines with stages, agents, parameters, and plugins. Implement multi-branch pipelines and deployment automation.

aj-geddes/markdown-documentation

Master markdown formatting, GitHub Flavored Markdown, README files, and documentation formatting. Use when writing markdown docs, READMEs, or formatting documentation.

aj-geddes/nginx-configuration

Configure Nginx web server for high-performance reverse proxy, load balancing, SSL/TLS, caching, and API gateway functionality.

aj-geddes/nodejs-express-server

Build production-ready Express.js servers with middleware, authentication, routing, and database integration. Use when creating REST APIs, managing requests/responses, implementing middleware chains, and handling server logic.

aj-geddes/rest-api-design

Design RESTful APIs following best practices for resource modeling, HTTP methods, status codes, versioning, and documentation. Use when creating new APIs, designing endpoints, or improving existing API architecture.

aj-geddes/wireframe-prototyping

Create wireframes and interactive prototypes to visualize user interfaces and gather feedback early. Use tools and techniques to communicate design ideas before development.

相关技能