Back to Prompt Library
Coding
APIBackendRESTCoding

REST API Endpoint Generator

Scaffolds a complete, validated, well-documented REST API endpoint in any stack.

Best For

  • Backend developers scaffolding a new endpoint who want validation, error handling, and docs generated together instead of piecemeal.
  • Solo founders building an MVP API who need production-reasonable error responses without researching REST conventions from scratch.
  • Teams writing API specs before implementation who want a consistent starting template across endpoints.

Prompt Template

Design and implement a REST API endpoint for [ENDPOINT PURPOSE, e.g. 'user authentication', 'product search', 'order creation']. Stack: [LANGUAGE/FRAMEWORK, Node.js/Express, Python/FastAPI, etc.]. Include: (1) the route definition with HTTP method and path, (2) request validation (required fields, types, constraints), (3) business logic with inline comments, (4) success response with example JSON (200/201), (5) error responses for: 400 bad request, 401 unauthorized, 404 not found, 500 server error, (6) one middleware function for authentication/logging if relevant. Follow RESTful conventions. Add JSDoc or docstring comments.

Pro Tip

Specify your existing auth middleware or error-handling pattern in the prompt, otherwise the model will invent its own convention that won't match the rest of your codebase.

Example Output

A sample of what this prompt produces once you fill in the placeholders.

For a 'product search' endpoint on Node.js/Express, the output defines GET /api/products/search with query param validation for 'q' and 'limit', a search handler with inline comments, a 200 response with a sample JSON array of products, 400/404/500 error bodies, and a logging middleware function, all with JSDoc comments.

How to use this prompt

  1. Copy the prompt template using the button above.
  2. Paste it into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.).
  3. Replace all bracketed placeholders like [TOPIC] with your specific details.
  4. Send the prompt and refine the output as needed.