Client connections
Same-process calls
Call your API directly when the client and server run in the same process.
On this page
Use inProcessTransport() to call an implementation from the same JavaScript process. It runs validation, middleware, and the handler without making an HTTP request.
The example calls the server from Build a task API. Keep this client in server code: it imports the implementation directly.
import { createClient } from '@hulla/api/client'
import { inProcessTransport } from '@hulla/api/in-process'
import { contract } from './contract'
import { implementation } from './implementation'
const api = createClient(contract, {
transport: inProcessTransport(implementation),
})
const result = await api.createTask({
body: { title: 'Write the quick start' },
})
console.log(result.body.title) // Write the quick startThis is a zero-network call, not an HTTP simulation. Native JSON values pass directly instead of being stringified and parsed, so keep type-only JSON declarations JSON-compatible if the same contract also uses HTTP. Codecs still encode and decode their application values.
Because the local client imports the implementation, place it behind a server-only module boundary. Browser code should build a separate client from the same contract with fetchTransport() or another remote transport. Server and browser calls explains how to choose and place each client across full-stack frameworks.
Use ordinary functions when no contract lifecycle is needed. In-process transport is useful when a local caller should observe the same validation, middleware, declared statuses, errors, and cancellation behavior as a remote caller.