Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/finom/vovk
RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.
https://github.com/finom/vovk
controller decorators nestjs nextjs nextjs13 nodejs rest-api service threading worker
Last synced: 8 days ago
JSON representation
RESTful RPC for Next.js - Transforms Next.js into a powerful REST API platform with RPC capabilities.
- Host: GitHub
- URL: https://github.com/finom/vovk
- Owner: finom
- License: mit
- Created: 2023-07-12T19:42:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-15T17:04:11.000Z (24 days ago)
- Last Synced: 2024-10-19T08:40:22.308Z (20 days ago)
- Topics: controller, decorators, nestjs, nextjs, nextjs13, nodejs, rest-api, service, threading, worker
- Language: TypeScript
- Homepage: https://vovk.dev
- Size: 6.26 MB
- Stars: 44
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-list - vovk - Transforms Next.js into a powerful REST API platform with RPC capabilities. | finom | 44 | (TypeScript)
README
RESTful RPC for Next.js
Transforms Next.js into a powerful REST API platform with RPC capabilities.
ℹ️ An ultimate version of Vovk.ts is coming soon. Stay tuned!
Documentation
Discord
Code Examples
vovk-zod
vovk-hello-world
vovk-react-native-example
Example back-end Controller Class:
```ts
// /src/modules/post/PostController.ts
import { get, prefix, type VovkRequest } from 'vovk';
import PostService from './PostService';
@prefix('posts')
export default class PostController {
/**
* Create a comment on a post
* POST /api/posts/:postId/comments
*/
@post(':postId/comments')
static async createComment(
// decorate NextRequest type with body and query types
req: VovkRequest<
{ content: string; userId: string },
{ notificationType: 'push' | 'email' }
>,
{ postId }: { postId: string } // params
) {
// use standard Next.js API to get body and query
const { content, userId } = await req.json();
const notificationType = req.nextUrl.searchParams.get('notificationType');
// perform the request to the database in a custom service
return PostService.createComment({
postId, content, userId, notificationType,
});
}
}
```Example component that uses the auto-generated client library:
```tsx
'use client';
import { useState } from 'react';
import { PostController } from 'vovk-client';
import type { VovkReturnType } from 'vovk';
export default function Example() {
const [response, setResponse] = useState>();
return (
<>
setResponse(
await PostController.createComment({
body: {
content: 'Hello, World!',
userId: '1',
},
params: { postId: '69' },
query: { notificationType: 'push' }
})
)}
>
Post a comment
{JSON.stringify(response)}
>
);
}
```Alternatively, the resource can be fetched wit the regular `fetch` function:
```ts
fetch('/api/posts/69?notificationType=push', {
method: 'POST',
body: JSON.stringify({
content: 'Hello, World!',
userId: '1',
}),
})
```