Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt

Use this file to discover all available pages before exploring further.

Starting from Expo SDK 50 and App Router v3, Expo lets you define API routes directly inside your Expo project. Because Elysia is WinterTC-compliant, you can use it as the handler for those routes by exporting app.fetch under each HTTP method name.
1

Create a catch-all API route file

Create app/[...slugs]+api.ts in your Expo project.
2

Define your Elysia server and export method handlers

// app/[...slugs]+api.ts
import { Elysia, t } from 'elysia'

const app = new Elysia()
  .get('/', 'hello Expo')
  .post('/', ({ body }) => body, {
    body: t.Object({
      name: t.String()
    })
  })

export const GET = app.fetch
export const POST = app.fetch

Route prefix

If you place your Elysia server in a subdirectory (e.g. app/api/[...slugs]+api.ts), set the prefix option to match:
// app/api/[...slugs]+api.ts
import { Elysia, t } from 'elysia'

const app = new Elysia({ prefix: '/api' })
  .get('/', 'Hello Expo')
  .post('/', ({ body }) => body, {
    body: t.Object({
      name: t.String()
    })
  })

export const GET = app.fetch
export const POST = app.fetch

End-to-end type safety with Eden

Add Eden Treaty for full type safety between your Expo app and backend.
1

Export the app type from your API route

// app/[...slugs]+api.ts
import { Elysia } from 'elysia'

const app = new Elysia()
  .get('/', 'Hello Expo')

export type app = typeof app

export const GET = app.fetch
export const POST = app.fetch
2

Create a Treaty client

// lib/eden.ts
import { treaty } from '@elysia/eden'
import type { app } from '../app/[...slugs]+api'

export const api = treaty<app>('localhost:3000/api')
3

Use the client in your components

// app/page.tsx
import { api } from '../lib/eden'

export default async function Page() {
  const message = await api.get()

  return <h1>Hello, {message}</h1>
}

Deployment

You can deploy your Expo app with Elysia using the experimental Expo server runtime. Run expo export to produce an optimized build — the Elysia handler will be bundled at dist/server/_expo/functions/[...slugs]+api.js.
Expo functions are treated as Edge functions, not persistent servers. Running the function directly does not allocate a port. Use one of the supported Expo function adapters: Express, Netlify, or Vercel.

pnpm peer dependencies

If you use pnpm, install peer dependencies manually:
pnpm add @sinclair/typebox openapi-types

Build docs developers (and LLMs) love