0.5.2 • Published 5 months ago
@delight-rpc/next.js v0.5.2
@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>