Skip to main content

Server Functions

Create type-safe server functions that can be called from the client with full end-to-end type safety.

createServerFn

Create a server function with automatic serialization, RPC, and type safety.

Method Configuration

'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'
HTTP method for the server function.Default: 'GET'

Server Function Builder

Chainable builder API for creating server functions.

.middleware()

Add middleware to process requests and responses.

.inputValidator()

Validate input data with Zod, Valibot, or custom validators.

.handler()

Define the server function implementation.

Handler Context

The handler function receives a context object:
ValidatedInput
Validated input data (if inputValidator is used).
ServerFnContext
Combined context from middleware and global context.
Request
The underlying HTTP request object.
AbortSignal
Abort signal for cancelling the request.

Calling Server Functions

From Client

From Route Loaders

From Other Server Functions

Middleware

Create reusable middleware for server functions.

createMiddleware

Authentication Middleware

Database Transaction Middleware

Error Handling

Try-Catch

Client Error Handling

File Uploads

Handle file uploads with FormData.

Examples

CRUD Operations

Authenticated API