Skip to content

Chapter 6 of 7

APIs, Data, and Infrastructure

Claude Code can scaffold and modify the moving parts of a typical web application. For new endpoints, a complete prompt looks like "Create a [GET/POST/PUT/DELETE] endpoint at [path] that [behavior]. It should validate [inputs] and return [response format]," and the same shape extends to OpenAPI documentation: "Generate OpenAPI/Swagger documentation for the [endpoint or file], including request/response schemas and example payloads." For GraphQL services, "Generate GraphQL schema types for [entities] with queries for [list/find], mutations for [create/update/delete], and proper resolver hints" produces a coherent starting point. For real-world usage, prompts like "Add cursor-based pagination to the [endpoint] returning [per_page] items per page with a next_cursor for subsequent requests" and "Add filtering and sorting to [endpoint] so users can filter by [fields], sort by [columns], and paginate results with [limit/offset or cursor]" give Claude the parameters it needs. To make endpoints robust, use "Add input validation to [endpoint/form] ensuring [field constraints]. Return descriptive validation errors for each invalid field." Rate limiting, caching, and resilience each have natural prompt patterns: "Add rate limiting to [endpoint] allowing [N] requests per [time window] per [user/IP], returning a 429 with retry-after header when exceeded"; "Add caching to [function/endpoint] with a [N minute] TTL, using [Redis/in-memory/HTTP cache headers] and cache invalidation for [events]"; and "Add exponential backoff retry logic to [API call/operation] with [max N retries], jitter, and logging of each attempt."

For data work, prompts should describe the desired outcome in concrete terms. Database work begins with a design prompt: "Design a normalized database schema for [feature/application] with tables, columns, data types, constraints, and foreign key relationships," and changes use the template "Create a migration to [add/modify/remove] [column/table] with [data type and constraints] following the existing migration conventions." Soft deletes, queries, and seed data all have canonical prompts: "Add soft delete functionality to [model] so records are marked deleted_at rather than removed, and all queries exclude soft-deleted records"; "Write a SQL query that [returns/aggregates/joins] [data description], optimized for [read performance / correctness / clarity]"; "Create a seeder for [model] with [N] realistic sample records covering [edge cases / varied scenarios]"; and "Generate [N] realistic mock records for [entity] in [JSON/SQL/CSV] format, varying the fields to cover different scenarios." Slow queries benefit from "This query is slow: [paste query]. Analyze it and rewrite it to be more efficient. Suggest any indexes that should be added."

Beyond the request layer, Claude can wire up jobs, uploads, auth, observability, and deployment. Useful prompts include "Create a background job that [behavior] triggered by [event], with retry logic, error handling, and progress logging"; "Add file upload support for [endpoint] accepting [file types] up to [size], storing in [S3/local disk], and validating file contents"; "Implement [JWT/session/OAuth] authentication for [framework], including login, logout, token refresh, and protected route middleware"; "Create a webhook handler for [service] that validates the signature, processes [event types], and responds within 5 seconds"; and "Create a data pipeline that [reads from source], [transforms data], and [writes to destination], handling errors and partial failures." For observability, "Add metrics, tracing, and structured logging to [service/endpoint] so we can monitor request rates, latency, and error rates" and "Define alerting rules for [service] that trigger when [error rate / latency / queue depth] exceeds [threshold] for [duration]" cover the major practices, and "Add structured logging to [file/function] that logs [events] with appropriate log levels (debug/info/warn/error)" handles the logging details. For delivery, the prompt "Create a [GitHub Actions / GitLab CI] workflow that runs [tests/builds/deploys] on [trigger events] for this [framework] project" produces a working starter workflow, while "Create a Dockerfile for this [language/framework] app that is optimized for production with a multi-stage build" handles containerization. A health check is one line: "Add a /health endpoint that checks [database connectivity / external service availability / disk space] and returns status 200 OK or 503 with details."

All chapters
  1. 1Getting Started with Claude Code
  2. 2Project Context and Configuration
  3. 3Reading, Searching, and Understanding Code
  4. 4Writing, Editing, and Refactoring Code
  5. 5Testing, Debugging, and Code Review
  6. 6APIs, Data, and Infrastructure
  7. 7Architecture, Documentation, and Release Workflow

Drill it

Reading is not remembering. These come from the Claude Code Prompts deck:

Q

What is Claude Code?

Claude Code is Anthropic's official AI-powered CLI tool that helps developers write, edit, debug, and understand code directly in the terminal.

Q

How do you start Claude Code?

Run `claude` in your terminal from any project directory to start an interactive session with the AI assistant.

Q

What is the key benefit of working in Claude Code's agentic mode?

Claude Code can read files, write code, run tests, and execute shell commands autonomously, completing complex multi-step tasks end-to-end.

Q

How do you give Claude Code access to your entire project?

Navigate to your project root before starting Claude Code — it will automatically have context of all files in the working directory.