Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/bundlejs-api.
Something went wrong. Try again.
description: Endpoint development rules applyTo: "edge/endpoints/**" #
Endpoint Development (edge/endpoints) #
Each endpoint lives in:
endpoints/{resource}/{action}/
- definition.ts (contract: route/methods/schemas)
- handler.ts (middleware + handler)
Definition contract #
- Export a default object that satisfies
EndpointDefinition. - Use
Methods: [...] as const. - Model both GET query and POST JSON when relevant.
Inputshould accept the raw source and may transform (Zod pipes/transforms allowed).Outputshould be the final response envelope schema.
Example shape:
- Name: string
- Route: string
- Methods: readonly HTTP methods
- Input: zod schema (often
QuerySchema.or(JsonSchema)) - Output: zod schema
- Schemas: { Query?, Json?, Param?, Header?, Cookie?, Form? }
Handler pattern #
- Export
Middlewareas an array ofEndpointMiddlewareHandler<AppEnv>[]. - Export
HandlerasEndpointHandler<AppEnv, typeof Definition>usingasync function (c). - Default-export
Handler.
Middleware order #
- Auth / correlation / request context (if applicable)
- Rate limiting / cache control (if applicable)
- Validation via
createValidator(target, schema) - Custom middleware
- Handler
Input handling #
- For GET, use validated input:
c.req.valid('query') - For POST, read JSON and then parse/transform into internal config as needed.
Responses #
- Use response helpers from
@utils/response. - Helpers return tuples intended to be spread into
c.json(...):return c.json(...ok(data))return c.json(...badRequest(path, message))
- It’s fine to add extra headers via
c.header(...)before returning.
Logging #
- Prefer request-correlated logging (use the correlation middleware helpers if present).
- Log both:
- operator/debug signals (cache hit/miss, durations)
- actionable failure context (safe error message, not secrets)
Educational clarity #
- If you implement non-trivial request parsing (encoding, compression, regex), explain it step-by-step with a small ASCII flow.
Related instructions #
edge-shared.instructions.md— rules for shared modules used by endpointstesting.instructions.md— test conventions and edge casestypescript.instructions.md— type and style conventions
Related guides #
.agents/guides/endpoint-architecture.md— architectural reference for endpoint patterns, middleware, response envelopes, and query processing