Skip to content

delight-rpc/next.js

Repository files navigation

@delight-rpc/next.js

Install

npm install --save @delight-rpc/next.js
# or
yarn add @delight-rpc/next.js

Usage

// api.d.ts
interface IAPI {
  echo(message: string): string
}

// src/pages/api/rpc.ts
import { createServer } from '@delight-rpc/next.js'

const api: IAPI = {
  echo(message: string): string {
    return message
  }
}

export default createServer(api, {})

API

createServer

function createServer<IAPI>(
  api: DelightRPC.ImplementationOf<IAPI>
, options?: {
    basicAuth?: (username: string, password: string) => PromiseLike<boolean> | boolean
    parameterValidators?: DelightRPC.ParameterValidators<IAPI>
    version?: `${number}.${number}.${number}`
    ownPropsOnly?: boolean
    channel?: string | RegExp | AnyChannel
  }
): (req: NextApiRequest, res: NextApiResponse) => Promise<void>