Docs

Migrate a backend

Migrate an API from Express, Fastify, Hono, or Elysia. The route handlers become chainable Nifra routes; request validation becomes part of the route contract; and the same app can serve a typed client on Bun, Node, Deno, or an edge runtime.

Keep your database, service layer, and domain logic. Move one endpoint at a time, translate its request and response shape, then point the existing frontend at the new endpoint. Nifra can stay backend-only or mount under a full-stack app. Use t.looseObject when you need to keep accepting undeclared body fields; t.object rejects them.

Map the backend primitives

Express / Fastify / Hono / ElysiaNifra
app.get(path, handler)server().get(path, handler); path params are inferred from the path
req / reply / framework contextc, with c.params, c.query, c.body, and the Web Request
res.json(x), reply.send(x), c.json(x)Return x for JSON, or return a Web Response
JSON Schema, TypeBox, or validator middlewareDeclare body, query, or params with t; validated values are typed in the handler
Set a status or response headerc.set.status and c.set.headers, or return a Response
Middleware and plugins.use() and the optional @nifrajs/middleware packages
Generated client types or a separate SDKclient<typeof app>() from @nifrajs/client, no codegen
OpenAPI and interactive API docsGenerate a document from the route schemas with nifra openapi

Express to Nifra

Replace req.params with c.params, body-parser middleware with a route schema, and res.status().json() with c.set.status plus a returned value. Keep Express middleware only where it is still needed during a staged migration.

TS
// Express
import express from "express"
const expressApp = express()
expressApp.get("/users/:id", (req, res) => res.json({ id: req.params.id, name: "Ada" }))
expressApp.post("/users", express.json(), (req, res) =>
  res.status(201).json({ id: crypto.randomUUID(), name: req.body.name }),
)

// Nifra
import { server } from "@nifrajs/core/server"
import { t } from "@nifrajs/schema"

export const app = server()
  .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
  .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
    c.set.status = 201
    return { id: crypto.randomUUID(), name: c.body.name }
  })

Fastify to Nifra

Move Fastify JSON Schema onto the route as Nifra's body, query, or params schema. Replace reply.code().send() with the response status and return value; move Fastify plugins to a Nifra plugin or .use() middleware where the behavior fits.

TS
// Fastify
import Fastify from "fastify"
type UserParams = { id: string }
type UserBody = { name: string }
const fastify = Fastify()
fastify.get<{ Params: UserParams }>("/users/:id", async (request, reply) =>
  reply.send({ id: request.params.id, name: "Ada" }),
)
fastify.post<{ Body: UserBody }>(
  "/users",
  {
    schema: {
      body: {
        type: "object",
        required: ["name"],
        properties: { name: { type: "string" } },
      },
    },
  },
  async (request, reply) =>
    reply.code(201).send({ id: crypto.randomUUID(), name: request.body.name }),
)

// Nifra
import { server } from "@nifrajs/core/server"
import { t } from "@nifrajs/schema"

export const app = server()
  .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
  .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
    c.set.status = 201
    return { id: crypto.randomUUID(), name: c.body.name }
  })

Hono to Nifra

The handler shape is close: c.req.param("id") becomes the typed c.params.id, and c.json() becomes a return. Move body parsing and validation into the route declaration so invalid input is rejected before the handler runs.

TS
// Hono
import { Hono } from "hono"
const legacy = new Hono()
legacy
  .get("/users/:id", (c) => c.json({ id: c.req.param("id"), name: "Ada" }))
  .post("/users", async (c) => {
    const body = await c.req.json<{ name: string }>()
    return c.json({ id: crypto.randomUUID(), name: body.name }, 201)
  })

// Nifra
import { server } from "@nifrajs/core/server"
import { t } from "@nifrajs/schema"

export const app = server()
  .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
  .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
    c.set.status = 201
    return { id: crypto.randomUUID(), name: c.body.name }
  })

Elysia to Nifra

Both use a chainable route API and TypeBox-shaped schemas. In Nifra, import t from @nifrajs/schema and declare the schema beside the handler; the handler receives a typed context and returns its response. This keeps the route contract available to Nifra's inferred client and other adapters.

TS
// Elysia
import { Elysia, t as elysiaT } from "elysia"
const legacy = new Elysia()
  .get("/users/:id", ({ params }) => ({ id: params.id, name: "Ada" }))
  .post(
    "/users",
    ({ body }) => ({ id: crypto.randomUUID(), name: body.name }),
    { body: elysiaT.Object({ name: elysiaT.String() }) },
  )

// Nifra
import { server } from "@nifrajs/core/server"
import { t } from "@nifrajs/schema"

export const app = server()
  .get("/users/:id", (c) => ({ id: c.params.id, name: "Ada" }))
  .post("/users", { body: t.looseObject({ name: t.string() }) }, (c) => {
    return { id: crypto.randomUUID(), name: c.body.name }
  })

Connect the API to a frontend or another runtime

The backend app itself is fetch-compatible. A frontend can call it in-process during SSR with inProcessClient(app), while apiPrefix: "/api" also mounts the routes at /api/* over HTTP. The prefix is passed through by default: set apiStrip: true to mount backend routes declared as /users/*, or declare their full /api/users/* paths. The same app can be served through Bun, @nifrajs/node, @nifrajs/deno, or an edge fetch handler.

For the UI migration, see Migrate a frontend. For route schemas, middleware, and deployment details, continue to API & typed client, Plugins & middleware, and Deployment.