background

End-to-end typesafe APIs builder,Developer-first simplicity

oRPC is an open-source solution for building modern, typesafe APIs.Build robust, scalable APIs and expose them to the internet with typesafe clients and full OpenAPI support.

import { ,  } from '@orpc/server'
import {  } from '@orpc/zod'
import {  } from 'zod'
 
export type  = { ?: { : string } }
 
// global osw completely optional, needed when you want to use context
export const  /** os with ... */ = .<>()
 
export const  = .({
  : 
    .(
      .({
        : .(),
      }),
    )
    .(async (, , ) => {
      return {
        : `Hello, ${.}!`,
      }
    }),
 
  : .('/posts').({
    : 
      .({
        : '/{id}', // custom your OpenAPI
        : 'GET',
      })
      .(
        .({
          : .({}),
        }),
      )
      .(
        .({
          : .(),
          : .(),
          : .(),
        }),
      )
      .((, , ) => {
        if (!.) {
          throw new ({
            : 'UNAUTHORIZED',
          })
        }
 
        .(() => {
          // do something on success
        })
 
        return {
          : {
            : ., // from now user not undefined-able
          },
        }
      })
      .((, , ) => {
        return {
          : 'example',
          : 'example',
          : 'example',
        }
      }),
 
    : 
      .(
        .({
          : .(),
          : .(),
          : .().('image/*'),
        }),
      )
      .(async (, , ) => {
        . // file upload out of the box
 
        return {
          : 'example',
          : .,
          : .,
        }
      }),
  }),
})
 
// Expose apis to the internet with fetch handler
 
import {  } from '@orpc/server/fetch'
 
const  = ({
  ,
  : false, // set true will improve cold start times
})
 
// Modern runtime that support fetch api like deno, bun, cloudflare workers, even node can used
 
import {  } from 'srvx'
 
const  = ({
  () {
    return ({
      ,
      : {},
      : '/api',
    })
  },
  : 2206,
})
 
await .()
 
// biome-ignore lint/suspicious/noConsole: <explanation>
.(`🚀 Server ready at ${.}`)
 
//
//
import { ,  } from '@orpc/client'
import type {  } from 'examples/server'
 
const  = <typeof  /* or contract router */>({
  : 'http://localhost:2026/api',
  // fetch: optional override for the default fetch function
  // headers: provide additional headers
})
 
//  File upload out of the box
const  = await ..({
  : 'My Amazing Title',
  : 'This is a detailed description of my content',
  : (.('thumb') as HTMLInputElement).[0]!,
})
 
..
  • create
  • find
// typesafe and completion out of box try { const = await ..({ : 'example' }) } catch () { if ( instanceof ) { // handle error } }