Skip to content

Deno Integration

Deno provide a serverless execution environment for building fast, globally distributed applications that follow the Fetch API. For additional context, refer to the Fetch Server Integration guide.

Basic

ts
import { RPCHandler } from '@orpc/server/fetch'
import { CORSPlugin } from '@orpc/server/plugins'

const handler = new RPCHandler(router, {
  plugins: [
    new CORSPlugin()
  ]
})

Deno.serve(async (request) => {
  const url = new URL(request.url)

  if (url.pathname.startsWith('/rpc')) {
    const { response } = await handler.handle(request, {
      prefix: '/rpc',
      context: {} // Provide initial context if needed
    })

    if (response) {
      return response
    }
  }

  return new Response('Not found', { status: 404 })
})

INFO

The handler can be any supported oRPC handler, such as RPCHandler, OpenAPIHandler, or another custom handler.

Released under the MIT License.