Core

Route Handlers

Use passIt inside App Router API routes for reads, writes, dynamic paths, and service-specific forwarding.

Basic GET

ts
import { passIt } from "@pajarrahmansyah/passit"; import type { NextRequest } from "next/server"; export async function GET(req: NextRequest) { return passIt({ path: "/users", req }); }

PassIt forwards query parameters:

txt
/api/users?page=2 -> https://api.backend.com/users?page=2

Server-initiated routes

Omit req only when the upstream call does not depend on query params, request body, or client headers.

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

If your route accepts a NextRequest, pass it to PassIt unless you intentionally want to drop client input.

Mutations

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

Dynamic routes

ts
type Params = { params: Promise<{ id: string }>; }; export async function GET(req: NextRequest, { params }: Params) { const { id } = await params; return passIt({ path: `/users/${id}`, req }); }

Response transform

ts
return passIt({ path: "/users", req, response: (data) => ({ users: data.results, total: data.count, }), });

If normalize and response are both defined, response receives normalized data. Set normalize: false when you need raw backend data.

Typed config route

You can also import the config and use the typed passIt returned by defineConfig.

ts
import passit from "@/passit.config"; import type { NextRequest } from "next/server"; export async function GET(req: NextRequest) { return passit.passIt({ service: "auth", path: "/users/me", req }); }