REST for Next
Transforms Next.js into a powerful and extensible REST API platform.
Made with TypeScript, inspired by NestJS.
Website Documentation Interactive Examples vovk-zod vovk-hello-world vovk-react-native-example
Example back-end Controller Class:
import { get, prefix } from 'vovk';
@prefix('hello')
export default class HelloController {
/**
* Return a greeting from
* GET /api/hello/greeting
*/
@get('greeting')
static getHello() {
return { greeting: 'Hello world!' };
}
}
Example component that uses the auto-generated client library:
'use client';
import { useState } from 'react';
import { HelloController } from 'vovk-client';
import type { VovkClientReturnType } from 'vovk';
export default function Example() {
const [
serverResponse, setServerResponse,
] = useState<VovkClientReturnType<typeof HelloController.getHello>>();
return (
<>
<button
onClick={async () => {
setServerResponse(
await HelloController.getHello()
);
}}
>
Get Greeting from Server
</button>
<div>{serverResponse?.greeting}</div>
</>
);
}