Scan your whole stack
Are you using @rest-rpc/tanstack-query?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.8.1
@rest-rpc/tanstack-query was last scanned on 25 Nov 2026 at version 0.8.1. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.8.1 LATEST | 25 Nov 2026 | No rules fired |
| 0.8.0 | 25 Nov 2026 | No rules fired |
| 0.7.0 | 23 Nov 2026 | No rules fired |
| 0.6.0 | 21 Nov 2026 | Not shown |
| 0.5.0 | 18 Nov 2026 | Not shown |
Findings for v0.8.1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.8.1; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
Type-safe REST APIs, for developers and agents. Write a route once, and it's a validated HTTP endpoint, a typed client call, TanStack Query options, an OpenAPI operation and a tool for MCP servers and agent SDKs. Below are the common patterns, each a complete example. See the documentation for the rest, or llms.txt for agents.
@rest-rpc/server: routes and
serving. Server code, tests included, imports only this package.@rest-rpc/core: the client,
contracts and OpenAPI. Client code imports this package.@rest-rpc/tanstack-query:
TanStack Query options and keys.A route, an app and a typed client. The client here calls the app in the same process, which is also how to test it.
See Quickstart
import { createApp, createClient, route } from "@rest-rpc/server";
const router = {
hello: route.get("/hello").handler(() => ({ message: "Hello" })),
};
const app = createApp(router); // `export default app` to serve it on Bun, Deno or Workers
const client = createClient(router, {
origin: "http://localhost",
fetch: app.fetch,
});
const { status, body } = await client.hello();
console.log(status, body.message); // 200 "Hello", typed from the handler
A route without a method is a POST, and without a path it's at its keys in
the route tree. :name segments are string params.
See Route Builder
import { route } from "@rest-rpc/server";
import * as z from "zod";
const base = route.prefix("/api");
export const router = {
posts: {
list: base
.get("/posts")
.handler(() => [{ id: "1", title: "Hello", body: "First post" }]), // GET /api/posts
get: base.get("/posts/:id").handler(({ params }) => ({ id: params.id })), // params.id: string
create: base
.body(z.object({ title: z.string(), body: z.string() }))
.handler(({ body }) => ({ id: "2", title: body.title, body: body.body })), // POST /api/posts/create
},
};
Requests are validated before the handler runs, with any Standard Schema such
as Zod, Valibot or ArkType. An invalid request gets a 400. Params, query and
headers arrive as strings, so their schemas coerce.
See Validation
import { route } from "@rest-rpc/server";
import * as z from "zod";
const search = route
.get("/users/:id/posts")
.params(z.object({ id: z.coerce.number() }))
.query(
z.object({
sort: z.enum(["new", "top"]).optional(),
tags: z.array(z.string()).optional(),
}),
)
.headers(z.object({ "x-request-id": z.string() }))
.handler(({ params, query, headers }) => ({
userId: params.id, // number
sort: query.sort ?? "new",
tags: query.tags ?? [], // sent as tags[]=a&tags[]=b
requestId: headers["x-request-id"],
}));
Return the body, or respond() to also set the status, headers or cookies.
See Responses
import { createApp, createClient, route } from "@rest-rpc/server";
import * as z from "zod";
const create = route
.post("/posts")
.body(z.object({ title: z.string(), body: z.string() }))
.handler(({ body, respond }) => {
const post = {
id: crypto.randomUUID(),
title: body.title,
body: body.body,
};
return respond(post, {
status: 201,
headers: { location: `/posts/${post.id}` },
cookies: ["draft=; Max-Age=0"],
});
});
const router = { create };
const app = createApp(router);
const client = createClient(router, {
origin: "http://localhost",
fetch: app.fetch,
});
const { status, headers } = await client.create({
body: { title: "Hello", body: "First post" },
});
console.log(status, headers.location); // 201 "/posts/..."
Without .response(), responses are inferred from the handler and not
validated. Define them to validate them and document them in OpenAPI.
import { route } from "@rest-rpc/server";
import * as z from "zod";
const post = z.object({ id: z.string(), title: z.string(), body: z.string() });
const create = route
.post("/posts")
.body(z.object({ title: z.string(), body: z.string() }))
.response(post, { status: 201 })
.handler(({ body, respond }) =>
respond({ id: crypto.randomUUID(), ...body }, { status: 201 }),
);
Errors are thrown. An error the route defines is typed on the client, with its
code and data.
See Errors
import {
createApp,
createClient,
isDefinedError,
route,
safe,
} from "@rest-rpc/server";
import * as z from "zod";
const posts = new Map([["1", { id: "1", title: "Hello", body: "First post" }]]);
const router = {
get: route
.get("/posts/:id")
.error("POST_NOT_FOUND", {
status: 404,
data: z.object({ id: z.string() }),
})
.handler(({ params, errors }) => {
const post = posts.get(params.id);
if (!post) throw errors.POST_NOT_FOUND({ data: { id: params.id } });
return post;
}),
};
const app = createApp(router);
const client = createClient(router, {
origin: "http://localhost",
fetch: app.fetch,
});
const { error, data } = await safe(client.get({ params: { id: "2" } }));
if (isDefinedError(error)) console.log(error.code, error.data.id); // "POST_NOT_FOUND" "2"
else if (error) throw error;
else console.log(data.body.title);
routeError() defines an error once, to throw from any code and add to routes.
import { route, routeError } from "@rest-rpc/server";
import * as z from "zod";
const PostNotFound = routeError("POST_NOT_FOUND", {
status: 404,
data: z.object({ id: z.string() }),
});
const posts = new Map([["1", { id: "1", title: "Hello", body: "First post" }]]);
const findPost = (id: string) => {
const post = posts.get(id);
if (!post) throw new PostNotFound({ data: { id } });
return post;
};
const get = route
.get("/posts/:id")
.error(PostNotFound)
.handler(({ params }) => findPost(params.id));
Middleware runs around the handler and passes it values through context.
The server provides initial context, and metadata tells shared middleware
about each route.
import { createApp, route } from "@rest-rpc/server";
const base = route
.$meta<{ access: "public" | "signed-in" }>()
.$context<{ headers: Headers }>() // provided by the app below
.error("UNAUTHORIZED", { status: 401 })
.use(({ route, context, errors, next }) => {
const user = context.headers.get("authorization");
if (!user && route.meta?.access !== "public") throw errors.UNAUTHORIZED();
return next({ context: { user } });
});
const router = {
health: base
.get("/health")
.meta({ access: "public" })
.handler(() => "ok"),
me: base
.get("/me")
.meta({ access: "signed-in" })
.handler(({ context }) => context.user), // string | null
};
export default createApp(router, {
context: (request) => ({ headers: request.headers }), // or an object, such as { db }
});
Return an async iterable to stream events. The client iterates them.
import {
createApp,
createClient,
route,
sse,
sseEvent,
} from "@rest-rpc/server";
import * as z from "zod";
const messages = ["Ada liked your post", "Grace commented on your post"];
const router = {
notifications: route
.get("/notifications")
.response(sse(z.object({ message: z.string() }))) // optional, validates each event
.handler(async function* ({ signal }) {
for (const [i, message] of messages.entries()) {
if (signal.aborted) break;
yield sseEvent({ message }, { id: String(i) });
}
}),
};
const app = createApp(router);
const client = createClient(router, {
origin: "http://localhost",
fetch: app.fetch,
});
const { body } = await client.notifications();
for await (const event of body) console.log(event.id, event.data.message);
A body is JSON unless its content-type header says otherwise. FormData is
always sent as multipart/form-data, and a binary body arrives as a Blob.
import { createApp, createClient, route } from "@rest-rpc/server";
import * as z from "zod";
const router = {
upload: route
.post("/upload")
.body(z.instanceof(FormData))
.handler(({ body, respond }) =>
respond(`Got ${body.getAll("file").length} file(s)`, {
headers: { "content-type": "text/plain" },
}),
),
};
const app = createApp(router);
const client = createClient(router, {
origin: "http://localhost",
fetch: app.fetch,
});
const form = new FormData();
form.set("file", new Blob(["Hello"]), "hello.txt");
const { body } = await client.upload({ body: form });
console.log(body); // "Got 1 file(s)"
A codec sends another format, such as superjson to keep Date values. Pass
the same codecs to the client and the server.
See Custom Codecs
import { bodyCodec, createApp, createClient, route } from "@rest-rpc/server";
import superjson from "superjson";
const superjsonCodec = bodyCodec("application/vnd.superjson+json", {
serialize: (value) => superjson.stringify(value),
deserialize: async (body) => superjson.parse(await body.text()),
});
const router = {
post: route
.get("/post")
.handler(({ respond }) =>
respond(
{ title: "Hello", publishedAt: new Date() },
{ headers: { "content-type": "application/vnd.superjson+json" } },
),
),
};
const bodyCodecs = [superjsonCodec];
const app = createApp(router, { bodyCodecs });
const client = createClient(router, {
origin: "http://localhost",
fetch: app.fetch,
bodyCodecs,
});
const { body } = await client.post();
console.log(body.publishedAt instanceof Date); // true
Return a Fetch Response for what the builder can't describe, such as a
redirect. A response that never changes is .static(), built once at startup.
See Raw Responses
import { route } from "@rest-rpc/server";
const download = route
.get("/images/:id")
.handler(({ params }) =>
Response.redirect(`https://cdn.example.com/${params.id}`, 302),
);
const health = route.get("/health").static({ ok: true });
Interceptors run around every request, for app-wide work such as logging, API keys or CORS.
See Interceptors
import { createApp, interceptor, onError, route } from "@rest-rpc/server";
const logging = interceptor(async ({ request, next }) => {
const response = await next();
console.log(request.method, request.url, response.status);
return response;
});
const router = { hello: route.get("/hello").handler(() => "Hello") };
export default createApp(router, {
interceptors: [logging, onError((error) => console.error(error))],
});
@rest-rpc/server/node serves the same routes with node:http.
See Serving Routes
import { createServer } from "node:http";
import { route } from "@rest-rpc/server";
import { createApp } from "@rest-rpc/server/node";
const router = { hello: route.get("/hello").handler(() => "Hello") };
createServer(createApp(router)).listen(3000);
Serve the same routes from any framework: under one of its routes, or each registered on its router.
import { Hono } from "hono";
import { createCatchAllHandler, route } from "@rest-rpc/server";
const router = { hello: route.get("/hello").handler(() => "Hello") };
const handler = createCatchAllHandler(router);
const app = new Hono();
app.all("/api/*", async (c) => {
const result = await handler(c.req.raw, { mountPath: "/api" });
return result.matched ? result.response : c.notFound();
});
export default app;
A bundler macro runs extractContract() at build time, so the client gets the
routes' types without any server code. Bun runs macros itself, and Vite and
other bundlers with unplugin-macros. The client sections below use these
files.
// router.ts
import { route } from "@rest-rpc/server";
import * as z from "zod";
const posts = new Map([["1", { id: "1", title: "Hello", body: "First post" }]]);
export const router = {
posts: {
list: route.get("/posts").handler(() => [...posts.values()]),
get: route
.get("/posts/:id")
.error("POST_NOT_FOUND", { status: 404 })
.handler(({ params, errors }) => {
const post = posts.get(params.id);
if (!post) throw errors.POST_NOT_FOUND();
return post;
}),
create: route
.body(z.object({ title: z.string(), body: z.string() }))
.handler(({ body }) => {
const post = { id: crypto.randomUUID(), ...body };
posts.set(post.id, post);
return post;
}),
},
};
// contract.ts
import { extractContract } from "@rest-rpc/core";
import { router } from "./router.ts";
export function getContract() {
return extractContract(router);
}
// client.ts
import { createClient } from "@rest-rpc/core";
import { getContract } from "./contract.ts" with { type: "macro" };
export const client = createClient(getContract()); // the page's origin, or pass { origin }
// vite.config.ts
import Macros from "unplugin-macros/vite";
import { defineConfig } from "vite";
export default defineConfig({ plugins: [Macros()] });
Headers for every request, the server's mount path, and interceptors around each request.
See Fetch Client
// client.ts
import { clientInterceptor, createClient } from "@rest-rpc/core";
import { getContract } from "./contract.ts" with { type: "macro" };
const logging = clientInterceptor(async ({ request, next }) => {
const response = await next();
console.log(request.method, request.url, response.status);
return response;
});
export const client = createClient(getContract(), {
origin: "https://api.example.com",
mountPath: "/api",
globalHeaders: {
authorization: () => `Bearer ${localStorage.getItem("token")}`,
},
interceptors: [logging],
});
Query and mutation options for each route, with typed keys. fetch() calls a
route directly, such as in a router loader.
See TanStack Query
// client.ts
import { createClient } from "@rest-rpc/core";
import { createTanstackQueryUtils } from "@rest-rpc/tanstack-query";
import { getContract } from "./contract.ts" with { type: "macro" };
export const client = createClient(getContract());
export const queryUtils = createTanstackQueryUtils(client); Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.