Reference

API Reference

Reference exported functions, route options, config types, retry settings, normalization settings, and hook payloads.

Exports

ts
import { createPassIt, defineConfig, passIt } from "@pajarrahmansyah/passit"; import { withPassIt } from "@pajarrahmansyah/passit/next";

defineConfig

OptionTypeRequiredDefaultDescription
baseUrlstringYesNoneReal backend base URL, no trailing slash.
http"fetch" | "axios"No"fetch"HTTP adapter.
headersRecord<string, string>No{}Static headers injected on every request.
timeoutnumber | falseNo5000Timeout in milliseconds.
retryRetryConfigNoNoneRetry policy.
normalizeboolean | NormalizeConfigNoNoneNormalize success and/or errors.
hooksHooksConfigNoNoneLogging and observability hooks.

defineConfig(config) validates the config, registers it globally for package-level passIt, and returns a typed { passIt } helper bound to that config.

createPassIt

createPassIt(config) accepts the same config shape as defineConfig, but does not register it globally. Use it when you want explicit config ownership.

passIt

OptionTypeRequiredDescription
pathstringYesBackend endpoint path.
reqNextRequestNoIncoming Next.js request object. Pass it to forward query params, body, and client headers.
servicestringNoService key for multi-service config.
baseUrlstringNoRoute-level base URL override.
headersRecord<string, string>NoExtra headers for this route.
timeoutnumber | falseNoRoute timeout override.
retryRetryConfigNoRoute retry override.
normalizeboolean | NormalizeConfigNoRoute normalization override.
hooksHooksConfig & { override?: boolean }NoRoute-level hooks.
response(data: unknown) => unknownNoTransform data after normalization. Set normalize: false when the transformer needs raw upstream data.

Forwarding switch

req is optional. Passing it tells PassIt to forward client input.

ts
export async function GET(req: NextRequest) { return passIt({ path: "/users", req }); }

Omitting it creates a server-initiated request with no forwarded query params, body, or client headers.

ts
export async function GET() { return passIt({ path: "/health" }); }

Types

ts
type HttpLib = "fetch" | "axios"; type RetryConfig = { times: number; onStatus: number[]; }; type NormalizeConfig = { success?: boolean; error?: boolean; }; type NormalizedSuccess<T = unknown> = { success: true; status: number; data: T; }; type NormalizedError = { success: false; status: number; message: string; };

RetryConfig.onStatus accepts any status codes you choose. Retry also fires on network errors and adapter exceptions.

Hook payloads

ts
type HookRequest = { method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; path: string; headers: Record<string, string>; }; type HookResponse = { status: number; path: string; data: unknown; duration: number; }; type HookError = { status: number; path: string; message: string; };