Skip to main content
The frontend never hand-types a URL or a request body. Three things come from the backend:

Generate the route manifest

The scaffold’s dev, build, typecheck and xano:deploy scripts run it first, and npm run xano:check fails when the committed file is stale. Commit xano/routes.gen.ts. Run npx @xano/sdk routes ./xano/index.ts without --emit to list every address the file carries: each route in its api:<canonical>/<name> form, and each realtime socket, channel and MCP server with the call that builds it. With --json the listing returns all four kinds. A route key is "<VERB> <name>", the endpoint’s own identity: "GET posts/{id}", "POST posts". When two API groups both hold the same verb and name, those endpoints are keyed "<group>:<VERB> <name>" instead.

Call an endpoint

  • routePath fills and encodes path params. Keys and {param} names are checked at compile time, so a renamed endpoint stops compiling instead of returning a 404.
  • Fetch the absolute URL, never a bare path. routePath returns a path such as /api:<canonical>/posts/1. A dev server proxies that path to the backend, but the published site answers it with its own index.html, so a bare path works in development and breaks live. routeUrl(path, baseUrl?) puts the backend in front: baseUrl when given, else the window.XANO_HOST every publish injects, else nothing (the path as it is, for a dev server that proxies). A /tenant/<name> base keeps its prefix.
  • routeQuery builds the query string for a GET, typed by RouteInputs[key], with no SDK runtime. It drops path params and encodes lists and objects the way the endpoint reads them: `${routeUrl(routePath("GET search"), XANO_HOST)}?${routeQuery("GET search", { tags: ["a", "b"] })}`.
  • Import defs as types only. import type erases to nothing. Importing a def as a value runs its s.* and c.* calls at load time and pulls the SDK runtime into the bundle (about 65 kB gzipped).
  • InferResponse follows the stack. A db.get response is Row | null, a db.add is the written row, and an object-literal response has those keys. Where the shape cannot be known statically, it is unknown; declare responseShape on the query to fix every caller. A filter chain folds into the type: withFilters(ref("rows"), fl.first()) is the row.
  • A call carries its target’s shape. s.function.run with a def handle binds the target’s InferResponse. s.function.call and s.tool.call hand back an error envelope instead of raising, so they bind InferResponse<target> | CallErrorEnvelope: branch on .code before you read a field.
  • InferRow<typeof table> gives a table’s row type, for props and state.

The backend URL

npm run xano:deploy writes the Xano Engine’s URL into .env.local as VITE_XANO_HOST; restart the dev server to pick it up. A deploy with --static instead injects the backend URL into the built HTML as window.XANO_HOST, so one build serves any backend with no rebuild. The XANO_HOST constant above reads both. See Frontend hosting.

Validate at runtime with zod

The types check what you send at compile time. To validate data at runtime too, install the zod add-on:
It adds ROUTE_SCHEMAS, CHANNEL_SCHEMAS and MESSAGE_SCHEMAS to routes.gen.ts under the same keys, each checked against its type when you type-check:

Realtime

When the workspace has realtime servers, the same file exports socketUrl() and channelPath(), plus ChannelInputs and MessageInputs for their params and payloads:
socketUrl turns a tenant base URL into the socket’s own address form, which a frontend cannot build by hand. A listen-only client must send { action: "ping" } every few minutes, or the idle socket is closed. For code that already holds the host, socketPath(server, { tenant? }) returns the path alone (/ws/<canonical>), and mcpPath() does the same for an MCP server. The tables these helpers read are exported too: REALTIME_SERVERS, CHANNELS and MCP_SERVERS, keyed by RealtimeServerName, ChannelName and McpServerName (RouteName for ROUTES).

MCP servers

When the workspace has MCP servers, the file also exports mcpUrl(), the frontend’s equivalent of mcpServer().getUrl(). It lifts a tenant base URL the same way:
This is an address to show a user or hand to an MCP client. The endpoint answers browser requests too (access-control-allow-origin: *), so per-entry auth and the server’s oauth are what keep it private.

Next