Secure API Request Handler
A prompt that makes the model write an API route the way a security-conscious reviewer would want it: validated input, safe data access, uniform errors.
Because the requirements are listed as a checklist, the model addresses each one instead of producing a happy-path handler that trusts the request body.
Prompt template
Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.
Example input
When to use it
- Adding a new endpoint to an Express or Fastify service
- Generating boilerplate you will then review and tighten
- Teaching juniors what a defensive handler looks like
- Standardizing error shapes across a codebase
Best practices
- Specify the validation library and the exact fields and constraints.
- Ask for parameterized queries or an ORM, never string-built SQL.
- Define the error response shape once and reuse it.
- Always review generated auth and rate-limit code before shipping.
Common mistakes
- Assuming generated code is secure without review or tests.
- Not mentioning authentication, so the route is open by default.
- Returning raw error messages that leak internals.
FAQs
Is the generated code production ready?
Treat it as a strong first draft. Review authentication, authorization and rate limiting, and add tests.
Can I use it for Next.js route handlers?
Yes. Change the first line to "Next.js App Router route handler" and ask for NextResponse returns.
Does Zod prevent SQL injection?
No. Zod validates shape. Injection is prevented by parameterized queries or an ORM, which is why the template requires both.