Technical
How I Use Claude Code to Build a FastAPI Endpoint in 10 Minutes
Every client project needs endpoints. Login, signup, data fetch, webhook receivers. If each one takes an hour, a small API eats a full week. I refused to pay that tax. Here is how I use Claude Code to drop a production-quality FastAPI endpoint into my codebase in about ten minutes.
The Workflow
I do not ask Claude Code to 'build an API.' That produces generic garbage. I ask it to add one endpoint that follows the patterns already in my repo. The agent reads the existing router files, learns my conventions, and writes code that fits.
My prompt looks like this:
Add a GET /subscribers/{id} endpoint to src/routers/subscribers.py.
Follow the pattern in src/routers/posts.py. Return 404 if not found.
Add a matching Pydantic response model in src/models.py.That is it. Three sentences. The agent handles the rest.
What Claude Code Actually Does
It opens src/routers/posts.py and reads my conventions: router prefix, tags, async handler signature, typed response. It opens src/models.py and sees my existing Pydantic models. It writes the new endpoint and the response model in matching style.
Then it runs the test suite. If tests fail, it iterates. If tests pass, it shows me the diff.
@router.get('/{subscriber_id}', response_model=SubscriberResponse)
async def get_subscriber(subscriber_id: str) -> SubscriberResponse:
item = db.get_item(Key={'pk': f'SUB#{subscriber_id}'})
if 'Item' not in item:
raise HTTPException(status_code=404, detail='Subscriber not found')
return SubscriberResponse(**item['Item'])Why This Is Not 'Vibe Coding'
I am not yelling vague instructions at a magic box. I gave the agent three concrete constraints: the file, the pattern to mirror, and the error behavior. That is orchestration. I set direction and the agent executes within guardrails.
Compare this to typing the endpoint myself. I would copy the nearest similar handler, rename variables, forget to update one, run tests, fix the typo, run tests again. That dance takes twenty minutes even when I know exactly what I want. The agent does it in two.
The Ten Minute Breakdown
- 1 minute: write the prompt
- 2 minutes: agent reads code and writes changes
- 2 minutes: tests run and pass
- 3 minutes: I review the diff for subtle issues
- 2 minutes: I commit and move on
Three of those ten minutes are review. That is where humans still win. The agent writes faster than I do. But I still decide whether the code is actually correct.
See the FastAPI documentation for the patterns Claude Code learns from and the Claude Code docs for the orchestration model.
RELATED READING
The Consulting Shift I Am Making In Year Two
After a year of writing and building, my consulting practice is changing shape. Shorter engagements. Sharper outcomes.
ReadThe Frontend Shift: Shipping Less JavaScript In Year Two
A year ago I reached for Next.js for everything. This year I often reach for nothing.
ReadThe Serverless Lesson I Would Write On A Sticky Note
After a year of shipping serverless projects, one rule explains most of the wins and all of the losses.
Read