Skip to main content
Coding Prompts

Generate REST API Endpoint

Scaffold a complete REST API endpoint with validation, error handling, and documentation.

intermediateWorks with any modelCoding
Prompt
Generate a complete REST API endpoint using [FRAMEWORK].

**Endpoint details:**
- Purpose: [ENDPOINT_PURPOSE]
- HTTP method: [HTTP_METHOD]
- Route path: [ROUTE_PATH]
- Authentication required: [AUTH_REQUIRED]

**Request body schema:**
[REQUEST_BODY_SCHEMA]

**Expected response schema:**
[RESPONSE_SCHEMA]

Please generate:
1. **Complete endpoint code** — including route handler, middleware wiring (if needed), and any helper functions
2. **Input validation** — validate all required fields, types, formats, and constraints; return a `400` with a clear error message on invalid input
3. **Error handling** — handle expected failure cases (not found, conflict, unauthorized) with appropriate HTTP status codes and consistent error response shape
4. **Success response** — return the correct HTTP status code (200/201/204) with the response body
5. **JSDoc / docstring** — document the endpoint with parameter types, return type, and a brief description suitable for auto-generated API docs

Follow [FRAMEWORK] conventions and best practices throughout.

How to Use

Fill in the framework and endpoint details, then describe your request and response shapes in plain English or as a JSON example — either works. The generated code will be production-ready boilerplate that you can drop into your project, adjust the business logic inside the handler, and wire up to your router. Always review the validation logic against your actual data requirements before deploying.

Variables

VariableDescription
[FRAMEWORK]The web framework to use (e.g., Express / Node.js, FastAPI / Python, Spring Boot / Java, Gin / Go, Rails / Ruby, ASP.NET Core / C#)
[ENDPOINT_PURPOSE]A one-sentence description of what this endpoint does (e.g., "Create a new user account and send a verification email")
[HTTP_METHOD]The HTTP verb: GET, POST, PUT, PATCH, or DELETE
[ROUTE_PATH]The route path with path parameters in the framework's format (e.g., /users/:id for Express, /users/{id} for FastAPI)
[AUTH_REQUIRED]yes or no. If yes, specify the auth mechanism (e.g., JWT Bearer token, API key header, session cookie)
[REQUEST_BODY_SCHEMA]Describe or paste the expected request body fields, their types, and which are required vs. optional. Example: { "email": string (required), "password": string (required, min 8 chars), "name": string (optional) }
[RESPONSE_SCHEMA]Describe the success response body. Example: { "id": uuid, "email": string, "createdAt": ISO timestamp }

Tips

  • If you have an OpenAPI / Swagger spec, paste the relevant operation object instead of filling in the schema fields manually — the model can read it directly.
  • Specify your error response shape if your API already has a convention (e.g., { "error": { "code": string, "message": string } }) so the generated code stays consistent with your existing endpoints.