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.

executeApiRoute

función

Ejecuta un endpoint de API con sus guardas y validaciones y devuelve la respuesta JSON, o lanza un ApiError. Es la pieza de bajo nivel de dispatchApiRoute, que además normaliza errores. El orden es: Origin (desde 1.8, en toda mutación salvo con origin: "none"), Origin y CSRF de la sesión, rateLimit, auth, authorize, params, query, body, locals, handler y response. La respuesta usa el estado de status (200 por defecto); con 204, sin cuerpo.

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

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

Firma #

ts
function executeApiRoute<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, rawParams?: unknown): 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, para Origin y CSRF.

rawParams unknown optional

Parámetros de la ruta sin validar.

Returns #

Promise<Response>

La respuesta del endpoint.

Throws #

ApiError

Con INVALID_ORIGIN, RATE_LIMITED, UNAUTHENTICATED, FORBIDDEN, INVALID_PARAMS, INVALID_QUERY, INVALID_BODY, UNSUPPORTED_MEDIA_TYPE, BODY_TOO_LARGE, INVALID_RATE_LIMIT, INVALID_RESPONSE, INVALID_RESPONSE_STATUS (un status no admitido o combinado con contentType: "response" o, con 204, con response) o los de locals y del handler.

Example #

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

const response = await executeApiRoute(userRoute, context, sessions, { id: "123" });

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