Flask API Development

Flask API Development

Teaches an AI agent to build Flask REST APIs with blueprints, SQLAlchemy models, JWT authentication, validation and error handling.

Skill files9 files

references/

scripts/

templates/

SKILL.md103 lines
1
---
2
name: flask-api-development
3
description: >
4
Develop lightweight Flask APIs with routing, blueprints, database integration,
5
authentication, and request/response handling. Use when building RESTful APIs,
6
microservices, or lightweight web services with Flask.
7
---
8
9
# Flask API Development
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Create efficient Flask APIs with blueprints for modular organization, SQLAlchemy for ORM, JWT authentication, comprehensive error handling, and proper request validation following REST principles.
22
23
## When to Use
24
25
- Building RESTful APIs with Flask
26
- Creating microservices with minimal overhead
27
- Implementing lightweight authentication systems
28
- Designing API endpoints with proper validation
29
- Integrating with relational databases
30
- Building request/response handling systems
31
32
## Quick Start
33
34
Minimal working example:
35
36
```python
37
# app.py
38
from flask import Flask, request, jsonify
39
from flask_cors import CORS
40
from flask_sqlalchemy import SQLAlchemy
41
from flask_jwt_extended import JWTManager
42
import os
43
44
app = Flask(__name__)
45
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'sqlite:///app.db')
46
app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY', 'dev-secret')
47
app.config['JSON_SORT_KEYS'] = False
48
49
db = SQLAlchemy(app)
50
jwt = JWTManager(app)
51
CORS(app)
52
53
# Request ID middleware
54
@app.before_request
55
def assign_request_id():
56
import uuid
57
request.request_id = str(uuid.uuid4())
58
59
# Error handlers
60
@app.errorhandler(400)
61
def bad_request(error):
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Flask Application Setup](references/flask-application-setup.md) | Flask Application Setup |
72
| [Database Models with SQLAlchemy](references/database-models-with-sqlalchemy.md) | Database Models with SQLAlchemy |
73
| [Authentication and JWT](references/authentication-and-jwt.md) | Authentication and JWT |
74
| [Blueprints for Modular API Design](references/blueprints-for-modular-api-design.md) | Blueprints for Modular API Design |
75
| [Request Validation](references/request-validation.md) | Request Validation |
76
| [Application Factory and Configuration](references/application-factory-and-configuration.md) | Application Factory and Configuration |
77
78
## Best Practices
79
80
### ✅ DO
81
82
- Use blueprints for modular organization
83
- Implement proper authentication with JWT
84
- Validate all user input
85
- Use SQLAlchemy ORM for database operations
86
- Implement comprehensive error handling
87
- Use pagination for collection endpoints
88
- Log errors and important events
89
- Return appropriate HTTP status codes
90
- Implement CORS properly
91
- Use environment variables for configuration
92
93
### ❌ DON'T
94
95
- Store secrets in code
96
- Use global variables for shared state
97
- Ignore database transactions
98
- Trust user input without validation
99
- Return stack traces in production
100
- Use mutable default arguments
101
- Forget to handle database connection errors
102
- Implement authentication in route handlers
103

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…