$npx -y skills add ancoleman/ai-design-components --skill implementing-api-patternsAPI design and implementation across REST, GraphQL, gRPC, and tRPC patterns. Use when building backend services, public APIs, or service-to-service communication. Covers REST frameworks (FastAPI, Axum, Gin, Hono), GraphQL libraries (Strawberry, async-graphql, gqlgen, Pothos), gRP
| 1 | # API Patterns Skill |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Design and implement APIs using the optimal pattern and framework for the use case. Choose between REST, GraphQL, gRPC, and tRPC based on API consumers, performance requirements, and type safety needs. |
| 6 | |
| 7 | ## When to Use This Skill |
| 8 | |
| 9 | Use when: |
| 10 | - Building backend APIs for web, mobile, or service consumers |
| 11 | - Connecting frontend components (forms, tables, dashboards) to databases |
| 12 | - Implementing pagination, rate limiting, or caching strategies |
| 13 | - Generating OpenAPI documentation automatically |
| 14 | - Choosing between REST, GraphQL, gRPC, or tRPC patterns |
| 15 | - Integrating authentication and authorization |
| 16 | - Optimizing API performance and scalability |
| 17 | |
| 18 | ## Quick Decision Framework |
| 19 | |
| 20 | ``` |
| 21 | WHO CONSUMES YOUR API? |
| 22 | ├─ PUBLIC/THIRD-PARTY DEVELOPERS → REST with OpenAPI |
| 23 | │ ├─ Python → FastAPI (auto-docs, 40k req/s) |
| 24 | │ ├─ TypeScript → Hono (edge-first, 50k req/s, 14KB) |
| 25 | │ ├─ Rust → Axum (140k req/s, <1ms latency) |
| 26 | │ └─ Go → Gin (100k+ req/s, mature ecosystem) |
| 27 | │ |
| 28 | ├─ FRONTEND TEAM (same org) |
| 29 | │ ├─ TypeScript full-stack? → tRPC (E2E type safety) |
| 30 | │ └─ Complex data needs? → GraphQL |
| 31 | │ ├─ Python → Strawberry |
| 32 | │ ├─ Rust → async-graphql |
| 33 | │ ├─ Go → gqlgen |
| 34 | │ └─ TypeScript → Pothos |
| 35 | │ |
| 36 | ├─ SERVICE-TO-SERVICE (microservices) |
| 37 | │ └─ High performance → gRPC |
| 38 | │ ├─ Rust → Tonic |
| 39 | │ ├─ Go → Connect-Go (browser-friendly) |
| 40 | │ └─ Python → grpcio |
| 41 | │ |
| 42 | └─ MOBILE APPS |
| 43 | ├─ Bandwidth constrained → GraphQL (request only needed fields) |
| 44 | └─ Simple CRUD → REST (standard, well-understood) |
| 45 | ``` |
| 46 | |
| 47 | ## REST Framework Selection |
| 48 | |
| 49 | ### Python: FastAPI (Recommended) |
| 50 | |
| 51 | **Key Features:** Auto OpenAPI docs, Pydantic v2 validation, async/await, 40k req/s |
| 52 | |
| 53 | **Basic Example:** |
| 54 | ```python |
| 55 | from fastapi import FastAPI |
| 56 | from pydantic import BaseModel |
| 57 | |
| 58 | app = FastAPI() |
| 59 | |
| 60 | class Item(BaseModel): |
| 61 | name: str |
| 62 | price: float |
| 63 | |
| 64 | @app.post("/items") |
| 65 | async def create_item(item: Item): |
| 66 | return {"id": 1, **item.dict()} |
| 67 | ``` |
| 68 | |
| 69 | See `references/rest-design-principles.md` for FastAPI patterns and `examples/python-fastapi/`. |
| 70 | |
| 71 | ### TypeScript: Hono (Edge-First) |
| 72 | |
| 73 | **Key Features:** 14KB bundle, runs on any runtime (Node/Deno/Bun/edge), Zod validation, 50k req/s |
| 74 | |
| 75 | **Basic Example:** |
| 76 | ```typescript |
| 77 | import { Hono } from 'hono' |
| 78 | import { zValidator } from '@hono/zod-validator' |
| 79 | import { z } from 'zod' |
| 80 | |
| 81 | const app = new Hono() |
| 82 | app.post('/items', zValidator('json', z.object({ |
| 83 | name: z.string(), price: z.number() |
| 84 | })), (c) => c.json({ id: 1, ...c.req.valid('json') })) |
| 85 | ``` |
| 86 | |
| 87 | See `references/rest-design-principles.md` for Hono patterns and `examples/typescript-hono/`. |
| 88 | |
| 89 | ### TypeScript: tRPC (Full-Stack Type Safety) |
| 90 | |
| 91 | **Key Features:** Zero codegen, E2E type safety, React Query integration, WebSocket subscriptions |
| 92 | |
| 93 | **Basic Example:** |
| 94 | ```typescript |
| 95 | import { initTRPC } from '@trpc/server' |
| 96 | import { z } from 'zod' |
| 97 | |
| 98 | const t = initTRPC.create() |
| 99 | export const appRouter = t.router({ |
| 100 | createItem: t.procedure |
| 101 | .input(z.object({ name: z.string(), price: z.number() })) |
| 102 | .mutation(({ input }) => ({ id: '1', ...input })) |
| 103 | }) |
| 104 | export type AppRouter = typeof appRouter |
| 105 | ``` |
| 106 | |
| 107 | See `references/trpc-setup-guide.md` for setup patterns and `examples/typescript-trpc/`. |
| 108 | |
| 109 | ### Rust: Axum (High Performance) |
| 110 | |
| 111 | **Key Features:** Tower middleware, type-safe extractors, 140k req/s, compile-time verification |
| 112 | |
| 113 | **Basic Example:** |
| 114 | ```rust |
| 115 | use axum::{routing::post, Json, Router}; |
| 116 | use serde::{Deserialize, Serialize}; |
| 117 | |
| 118 | #[derive(Deserialize)] |
| 119 | struct CreateItem { name: String, price: f64 } |
| 120 | |
| 121 | #[derive(Serialize)] |
| 122 | struct Item { id: u64, name: String, price: f64 } |
| 123 | |
| 124 | async fn create_item(Json(payload): Json<CreateItem>) -> Json<Item> { |
| 125 | Json(Item { id: 1, name: payload.name, price: payload.price }) |
| 126 | } |
| 127 | ``` |
| 128 | |
| 129 | See `references/rest-design-principles.md` for Axum patterns and `examples/rust-axum/`. |
| 130 | |
| 131 | ### Go: Gin (Mature Ecosystem) |
| 132 | |
| 133 | **Key Features:** Largest Go ecosystem, 100k+ req/s, struct tag validation |
| 134 | |
| 135 | **Basic Example:** |
| 136 | ```go |
| 137 | type Item struct { |
| 138 | Name string `json:"name" binding:"required"` |
| 139 | Price float64 `json:"price" binding:"required,gt=0"` |
| 140 | } |
| 141 | |
| 142 | r := gin.Default() |
| 143 | r.POST("/items", func(c *gin.Context) { |
| 144 | var item Item |
| 145 | if c.ShouldBindJSON(&item); err != nil { |
| 146 | c.JSON(400, gin.H{"error": err.Error()}); return |
| 147 | } |
| 148 | c.JSON(201, item) |
| 149 | }) |
| 150 | ``` |
| 151 | |
| 152 | See `references/rest-design-principles.md` for Gin patterns and `examples/go-gin/`. |
| 153 | |
| 154 | ## Performance Benchmarks |
| 155 | |
| 156 | | Language | Framework | Req/s | Latency | Cold Start | Memory |