@fougere/adapter-rest
Entity → REST routes.
Use it
npm install @fougere/adapter-rest
pnpm add @fougere/adapter-rest
bun add @fougere/adapter-rest
yarn add @fougere/adapter-rest
// fougere.config.ts
import '@fougere/adapter-rest';
export default defineFougere({
protocols: { rest: {} },
});
The import is what makes the word exist: without it, the editor and the boot both refuse it.
// fronds/blog/frond.config.ts
export default defineFrond({
operations: { 'post.list': { rest: { … } } },
protocols: { rest: { … } },
});
Every key each one admits: protocols.
What it extends
The interfaces of Fougere this package adds its words to, with declare module — see Interfaces to extend.
| interface | adds |
|---|---|
FougereProtocols | rest |
FougereOperationProtocols | rest |
FougereFrondProtocols | rest |
Entries: @fougere/adapter-rest
What you import
| name | |
|---|---|
generateRoutes | Generate REST route definitions from a fougere App — one route per operation, per address served. |
PREFIX | |
prefixOf | |
openApiOf | What this process serves on REST, as OpenAPI 3.1, read off its routes. |
describedAt | What REST publishes of itself when protocols: says so, or undefined for any other request. Ex: {prefix}/openapi.json, {prefix}/docs. |
describedPaths | The paths describedAt answers, for a router that mounts each one. |
Rest | The port REST's links stand in front of; a link throwing before inner.answer refuses the request. Ex: implements Partial<Rest> for a frond, extends Rest<NoteHandler> for a handler. |
restDoor | REST's door for one route: the one place a status is decided, read off the contract. |
Types
TypeScript types only — they do not run. Import them with import type to type your own code: a variable, a parameter, an option object.
| name | |
|---|---|
RouteDefinition | |
HttpMethod | |
ResponseResult | |
RestRoute | |
OpenApiDocument | OpenAPI 3.1 — the part of it this writes. |
DocsPage | |
RestRequest | What a host hands the REST door for one matched route — the body still to read, so the door reads it. |
RestInvocation | What a route's op is called with. |
RestResponse | An answer a link at REST's door may give in the op's place, declared in its return type. |