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: 29 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-11-11T22:45:30.000Z (about 1 month ago)
- Last Synced: 2024-11-13T20:43:55.236Z (29 days ago)
- Topics: controller, decorators, nestjs, nextjs, nextjs13, nodejs, rest-api, service, threading, worker
- Language: TypeScript
- Homepage: https://vovk.dev
- Size: 7.35 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',
}),
})
```