Skip to content
Meeko
Type to search the guides and the API reference. Open it from any page with / or Ctrl K; move with the arrow keys and open a result with Enter.
Get started

Contents

On this page

Not translated yet

This page has not been translated into English yet, so it is shown in Spanish.

dispatchApiRoute

función

Atiende una petición de API para un host propio: ejecuta el endpoint, normaliza los errores en { code, status, requestId }, informa los fallos 5xx a onError y añade x-request-id, la cookie de sesión y el token CSRF. Nunca rechaza. Desde 1.7, si el endpoint declara form y la petición es un formulario nativo, responde 303 See Other con el resultado en una cookie de un solo uso (salvo 403 por Origin o CSRF); executeApiRoute sigue aceptando sólo JSON.

ts
import { dispatchApiRoute } from "@meekojs/meeko/server";

Source code src/server/api/runtime.ts:145

Firma #

ts
function dispatchApiRoute<P extends Schema | undefined, Q extends Schema | undefined, B extends Schema | undefined, R extends Schema | undefined, S, L = undefined, T extends ApiSuccessStatus = ApiSuccessStatus>(definition: ApiRouteDefinition<P, Q, B, R, S, L, T>, context: RequestContext<S>, sessions: SessionManager, params?: unknown, onError?: ServerErrorObserver): Promise<Response>

Type parameters #

P extends Schema | undefined
Q extends Schema | undefined
B extends Schema | undefined
R extends Schema | undefined
S
L = undefined

Parameters #

definition ApiRouteDefinition<P, Q, B, R, S, L, T>

Endpoint declarado con defineApiRoute.

context RequestContext<S>

Contexto de la petición.

sessions SessionManager

Gestor de sesiones.

params unknown optional

Parámetros de la ruta sin validar.

onError ServerErrorObserver optional

Observador de los fallos internos.

Returns #

Promise<Response>

La respuesta final.

Example #

ts
import { dispatchApiRoute } from "@meekojs/meeko/server";
import userRoute from "./server/api/users/[id].get.js";

const response = await dispatchApiRoute(userRoute, context, sessions, { id: "123" }, (error, id) => console.error(id, error));

See also #

Was this page helpful?

Add a comment

It is sent when you choose “Yes” or “No”. Only the page, your answer and the comment are stored: no cookies and no personal data.

0 of 2000 characters

Edit on GitHub: packages/meeko/src/server/api/runtime.ts