---
name: rest-api-endpoint-designer
description: "A full endpoint contract before anyone writes a handler: route and method, validated request shape, success and error responses with the right status codes, and an OpenAPI definition if you want one. Use when a new REST endpoint needs its contract specified (route, request schema, validation, status codes, error bodies) before implementation starts. Do not use for GraphQL schemas, reviewing an existing API's performance, or writing the server code. Related topics: coding, api, rest."
---

# REST API Endpoint Designer

A full endpoint contract before anyone writes a handler: route and method, validated request shape, success and error responses with the right status codes, and an OpenAPI definition if you want one.

## When to use

Use this skill when a new REST endpoint needs its contract specified (route, request schema, validation, status codes, error bodies) before implementation starts. Do not use it for GraphQL schemas, reviewing an existing API's performance, or writing the server code.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Confirm the method matches REST semantics for the operation and set the success status code accordingly (200, 201, or 204).
3. Write the request schema with types, required fields, and each validation rule attached to the field it governs.
4. Define the success response with an example payload, adding pagination parameters and an envelope for list endpoints.
5. Give every selected error the same body shape with a code, message, and details, and state what triggers each.
6. When requested, write the OpenAPI 3.1 path item in YAML with schemas under components and referenced from the path.

## Inputs

- **Resource name** (free text, e.g. "orders")
- **HTTP method** (choose one: GET, POST, PUT, PATCH, DELETE)
- **Endpoint path** (free text, e.g. "/api/v1/orders/:id")
- **Authentication required** (choose one: Yes, No)
- **Query parameters** (longer free text)
- **Request body fields** (longer free text)
- **Validation rules** (longer free text)
- **Success response body** (longer free text)
- **Error cases to cover** (choose any: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 422 Validation Error, 500 Server Error)
- **Include OpenAPI definition** (choose one: Yes, No)

## Output

Sections for Endpoint, Request, and Responses in that order, with example payloads, followed by an OpenAPI 3.1 YAML code block when requested.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### REST Endpoint Design

Design one REST endpoint end to end.

- Resource name: {{Resource name}}
- HTTP method: {{HTTP method}}
- Endpoint path: {{Endpoint path}}
- Authentication required: {{Authentication required}}
- Query parameters: {{Query parameters}}
- Request body fields: {{Request body fields}}
- Validation rules: {{Validation rules}}
- Success response body: {{Success response body}}
- Error cases to cover: {{Error cases to cover}}
- Include OpenAPI definition: {{Include OpenAPI definition}}

Check the method against REST semantics first: GET and DELETE take no body, PUT replaces the whole resource, PATCH changes part of it, and a POST that creates returns 201 with a Location header. Define the request as a schema with types, required fields, and the validation rules attached to the fields they govern, so the error response can name the failing field. Define the success response with an example payload; for list endpoints add pagination parameters and a consistent envelope. Give every selected error a consistent body shape (code, message, details) and say what triggers it. State the auth scheme and which header carries it. When an OpenAPI definition is requested, write the path item in OpenAPI 3.1 YAML with the schemas under components and referenced from the path.

Return sections in this order: Endpoint (method, path, auth), Request (parameters, body schema, validation), Responses (success example, then one block per error with its trigger), and the OpenAPI YAML in a code block when requested.

## Pitfalls

- Returning 200 for a create, which hides the new resource's location and breaks clients that expect 201.
- Putting a request body on a GET or DELETE, which many proxies and clients drop silently.
- Using a different error body shape per status code, so every client has to special-case the parsing.
