Fresh logo

API Reference

This page lists all public exports from Fresh’s entry points.

Info

You can also explore Fresh’s full API documentation on JSR: @fresh/core

fresh

The main entry point for server-side code.

Typescript  
import { App, createDefine, HttpError, page, staticFiles } from "fresh";
Export Kind Description
App Class The main application class. See App.
staticFiles Function Middleware for serving static files. See Static Files.
createDefine Function Create type-safe define.* helpers. See Define Helpers.
page Function Return data from a handler to a page component. See Data Fetching.
HttpError Class Throw HTTP errors with status codes. See Error Handling.
cors Function CORS middleware. See cors.
csrf Function CSRF protection middleware. See csrf.
csp Function Content Security Policy middleware. See csp.
trailingSlashes Function Trailing slash enforcement middleware. See trailingSlashes.

Types:

Export Kind Description
Context / FreshContext Interface The request context passed to all middlewares and handlers.
PageProps Type Props received by page components (data, url, params, state, etc.).
Middleware / MiddlewareFn Type Middleware function type.
HandlerFn Type Single handler function type.
HandlerByMethod Type Object with per-method handler functions.
RouteHandler Type Union of HandlerFn and HandlerByMethod.
PageResponse Type Return type of page().
RouteConfig Interface Route configuration (routeOverride, skipInheritedLayouts, etc.).
LayoutConfig Interface Layout configuration (skipInheritedLayouts, skipAppWrapper).
Define Interface Type of the object returned by createDefine().
FreshConfig / ResolvedFreshConfig Interface App configuration types.
ListenOptions Interface Options for app.listen().
Island Type Island component type.
Method Type HTTP method union type.
RouteData Type Data type returned by route handlers via page().
Lazy / MaybeLazy Type Utility types for lazily-loaded routes and middleware.
CORSOptions Interface Options for cors().
CsrfOptions Interface Options for csrf().
CSPOptions Interface Options for csp().

fresh/runtime

Shared runtime utilities for both server and client code. Safe to import in islands.

Typescript  
import {
  asset,
  assetSrcSet,
  Head,
  HttpError,
  IS_BROWSER,
  Partial,
} from "fresh/runtime";
Export Kind Description
IS_BROWSER Constant true in the browser, false on the server. Use to guard browser-only code.
asset Function Add cache-busting query params to asset URLs. See Static Files.
assetSrcSet Function Apply asset() to all URLs in a srcset string.
Partial Component Mark a region for partial updates. See Partials.
Head Component Add elements to the document <head>. See element.
HttpError Class HTTP error class (re-exported from fresh).

fresh/dev

Development and build tools. Only used in dev.ts (legacy) or build scripts.

Typescript  
import { Builder } from "fresh/dev";
Export Kind Description
Builder Class Pre-Vite build system (legacy). See Builder.

Types:

Export Kind Description
BuildOptions Interface Options for new Builder().
ResolvedBuildConfig Interface Resolved build configuration.
OnTransformArgs / OnTransformOptions / TransformFn Type Build plugin hook types.