Backend

API Endpoint Template

A template for designing and implementing RESTful API endpoints with request/response contracts, authentication, validation, error handling, and rate limiting considerations.

Template Preview

Copy and use in your project

API: Implement [HTTP Method] /api/[resource]

As an API consumer, I want a well-documented endpoint for managing [resource] so that I can integrate [resource] operations into my application or automation workflow.

featureHIGH5 pts

Description

Implement a new API endpoint that supports [CRUD operation] for [resource]. The endpoint should follow RESTful conventions, include proper authentication, input validation with Zod schemas, and return standardized error responses. **Endpoint:** `[GET|POST|PUT|PATCH|DELETE] /api/[resource]` **Request Body (if applicable):** ```json { "field1": "string (required)", "field2": "number (optional)" } ``` **Response (200):** ```json { "id": "string", "field1": "string", "createdAt": "ISO-8601" } ``` **Error Responses:** 400 (validation), 401 (unauthorized), 403 (forbidden), 404 (not found), 429 (rate limited)

Acceptance Criteria

Given I send a valid request with proper authentication

When the server processes the request

Then I receive a 200/201 response with the expected JSON payload and correct Content-Type headers

Given I send a request with invalid or missing required fields

When the server validates the request body using Zod

Then I receive a 400 response with a detailed validation error message indicating which fields failed

Given I send a request without authentication or with an invalid API key

When the auth middleware processes the request

Then I receive a 401 response and no data is returned or modified

Given I exceed the rate limit of 60 requests per minute

When I send an additional request

Then I receive a 429 response with a Retry-After header indicating when I can make the next request

Given the endpoint is deployed

When I check the OpenAPI specification

Then the new endpoint is documented with request/response schemas, authentication requirements, and example payloads

Import directly into Codepylot

Skip the copy-paste. Codepylot has built-in templates you can use with one click, plus AI that generates even richer stories from your ideas.

Try Codepylot Free

Other Templates

Ready to build your AI agent workforce?

Describe what you want. Your agents write the code. You stay in control.