ToolypetMCP
intermediate5 minutescross hub

API Design & Security Setup

Design and secure a REST API: generate UUIDs for resources, set up JWT auth, configure CORS, and hash secrets.

apidesignsecurityjwtcorsuuid

このレシピの使いどころ

Set up a new REST API with security best practices from the start. Covers resource identification, authentication, authorization scopes, and cross-origin access.

ステップ

1

Generate resource IDs

プロンプト:Generate UUID v4 for API resource identifiers — use as primary keys instead of sequential IDs
2

Create auth secret

プロンプト:Generate API signing secret for JWT-based authentication
3

Design JWT with scopes

プロンプト:Generate a sample API JWT with scopes: read:users, write:users, read:posts
4

Configure API CORS

プロンプト:Generate CORS headers allowing the frontend origin with credentials and specific methods (GET, POST, PUT, DELETE)
5

Design API response format

プロンプト:Format a sample API response with the UUID IDs, pagination, and proper structure

よくある質問

Why use UUIDs instead of auto-increment IDs in APIs?

UUIDs prevent enumeration attacks (can't guess /users/2 from /users/1), work in distributed systems without coordination, and don't leak information about your data volume.

Should API keys or JWTs be used for auth?

API keys for server-to-server and simple integrations. JWTs for user authentication with claims/scopes. Many APIs use API keys for identification + JWTs for authorization.

関連レシピ