[]previous and next page

ServerFnOptions

Options of serverFn.

Options of serverFn.

Import#

ts
import type { ServerFnOptions } from "@shadow-js/dusk/server";

Signature#

ts
interface ServerFnOptions {
  /** `"POST"` (default) for anything that changes state. `"GET"` only for safe, idempotent reads. */
  readonly method?: "GET" | "POST";
  /** Input schema (any Standard Schema). Without one the input is untrusted `unknown`. */
  readonly input?: StandardSchemaV1;
  /** Middleware, outermost first; for example an authorization check. */
  readonly middleware?: readonly ServerFnMiddleware[];
  /** Also accept HTML form posts (`application/x-www-form-urlencoded` or multipart) for progressive enhancement. */
  readonly form?: boolean;
  /**
   * Whether browser calls may be sent in a batch with the calls of the same tick (one request for many
   * calls). Default `true`; `false` sends each call alone. Read by the build for the browser stub.
   */
  readonly batch?: boolean;
  /**
   * A mutation that also answers with the refreshed loader data of the page the browser is on, so the
   * router applies it without a second request. Read at run time. Default `false`.
   */
  readonly singleFlight?: boolean;
  /**
   * Guards that run before the input is validated and before the middleware and the handler: a
   * refused call never reaches its handler. One guard or an array (see `all`, `any`, `defineGuard`).
   * Guards see the request, not the input. A guard that returns `false` gives 403; a throw keeps its
   * status (an `HttpError` 401, 403, ...).
   */
  readonly guard?: Guard | readonly Guard[];
  /**
   * The `cache-control` of a successful answer. Default `no-store`. `public` is for GET functions only and is
   * private for a request that carries cookies or authorization. Errors are never cached.
   */
  readonly cacheControl?: CacheControlOption;
  /**
   * Rate limit for the calls that reach this function over HTTP, one token per call, whether the call
   * came alone or inside a batch (a batch of 25 calls takes 25 tokens). The bucket is per function and per
   * caller (the client address, or `key`); a call without a token is refused with the 429 of the rate limit
   * middleware (`retry-after`, `ratelimit-*`), and in a batch only that call is refused. A limiter, or
   * `{ limiter, key, cost }`. Calls from server code (`fn()`, `fn.invoke()`) are not charged.
   */
  readonly rateLimit?: ServerFnRateLimitOption;
  /**
   * The largest request body a call of this function reads, in bytes. Default: the app's `security.limits.maxBodyBytes`.
   * A larger value raises the limit for this function only, up to `security.limits.maxRouteBodyBytes`; a smaller one lowers
   * it. A call over the limit is a 413 with the JSON error envelope, and the function does not run. A batch call is bounded
   * by the app's limit, not by this one (call the function alone for a larger body).
   */
  readonly maxBodyBytes?: number;
}

Members#

Name Type Description
method? readonly method?: "GET" | "POST" "POST" (default) for anything that changes state. "GET" only for safe, idempotent reads.
input? readonly input?: StandardSchemaV1 Input schema (any Standard Schema). Without one the input is untrusted unknown.
middleware? readonly middleware?: readonly ServerFnMiddleware[] Middleware, outermost first; for example an authorization check.
form? readonly form?: boolean Also accept HTML form posts (application/x-www-form-urlencoded or multipart) for progressive enhancement.
batch? readonly batch?: boolean Whether browser calls may be sent in a batch with the calls of the same tick (one request for many calls). Default true; false sends each call alone. Read by the build for the browser stub.
singleFlight? readonly singleFlight?: boolean A mutation that also answers with the refreshed loader data of the page the browser is on, so the router applies it without a second request. Read at run time. Default false.
guard? readonly guard?: Guard | readonly Guard[] Guards that run before the input is validated and before the middleware and the handler: a refused call never reaches its handler. One guard or an array (see all, any, defineGuard). Guards see the request, not the input. A guard that returns false gives 403; a throw keeps its status (an HttpError 401, 403, ...).
cacheControl? readonly cacheControl?: CacheControlOption The cache-control of a successful answer. Default no-store. public is for GET functions only and is private for a request that carries cookies or authorization. Errors are never cached.
rateLimit? readonly rateLimit?: ServerFnRateLimitOption Rate limit for the calls that reach this function over HTTP, one token per call, whether the call came alone or inside a batch (a batch of 25 calls takes 25 tokens). The bucket is per function and per caller (the client address, or key); a call without a token is refused with the 429 of the rate limit middleware (retry-after, ratelimit-*), and in a batch only that call is refused. A limiter, or { limiter, key, cost }. Calls from server code (fn(), fn.invoke()) are not charged.
maxBodyBytes? readonly maxBodyBytes?: number The largest request body a call of this function reads, in bytes. Default: the app's security.limits.maxBodyBytes. A larger value raises the limit for this function only, up to security.limits.maxRouteBodyBytes; a smaller one lowers it. A call over the limit is a 413 with the JSON error envelope, and the function does not run. A batch call is bounded by the app's limit, not by this one (call the function alone for a larger body).