Back-end meta-framework for Next.js
Vovk examples
License: MIT
# Install the package
npm install vovk-examples
Update user (Zod)
Update user by ID with Zod validation
POST http://localhost:3000/api/users-zod/{id}
import { UserZodRPC } from 'vovk-examples';
const response = await UserZodRPC.updateUser({
params: {
id: "00000000-0000-0000-0000-000000000000"
},
body: {
name: "string",
age: 0,
email: "user@example.com"
},
query: {
notify: "email"
},
});
console.log(response);
/*
{
success: true
}
*/
Update user (Yup)
Update user by ID with Yup validation
POST http://localhost:3000/api/users-yup/{id}
import { UserYupRPC } from 'vovk-examples';
const response = await UserYupRPC.updateUser({
params: {
id: "string"
},
body: {
name: "string",
age: 0,
email: "user@example.com"
},
query: {
notify: "email"
},
});
console.log(response);
/*
{
success: true
}
*/
Update user (DTO)
Update user by ID with DTO validation
POST http://localhost:3000/api/users-dto/{id}
import { UserDtoRPC } from 'vovk-examples';
const response = await UserDtoRPC.updateUser({
params: {
id: "00000000-0000-0000-0000-000000000000"
},
body: {
name: "string",
age: 0,
email: "user@example.com"
},
query: {
notify: "email"
},
});
console.log(response);
/*
{
success: true
}
*/
Update user (Arktype)
Update user by ID with Arktype validation
POST http://localhost:3000/api/users-arktype/{id}
import { UserArktypeRPC } from 'vovk-examples';
const response = await UserArktypeRPC.updateUser({
params: {
id: "00000000-0000-0000-0000-000000000000"
},
body: {
age: 0,
email: "user@example.com",
name: "string"
},
query: {
notify: "email"
},
});
console.log(response);
/*
{
success: true
}
*/
Update user (Valibot)
Update user by ID with Valibot validation
POST http://localhost:3000/api/users-valibot/{id}
import { UserValibotRPC } from 'vovk-examples';
const response = await UserValibotRPC.updateUser({
params: {
id: "00000000-0000-0000-0000-000000000000"
},
body: {
name: "string",
age: 0,
email: "user@example.com"
},
query: {
notify: "email"
},
});
console.log(response);
/*
{
success: true
}
*/
Get a greeting
Get a greeting from the server
GET http://localhost:3000/api/hello-world/greeting
import { HelloWorldRPC } from 'vovk-examples';
const response = await HelloWorldRPC.getHello();
Post a greeting
Post a greeting to the server
POST http://localhost:3000/api/hello-world/greeting
import { HelloWorldRPC } from 'vovk-examples';
const response = await HelloWorldRPC.postHello();
Get a greeting using a service
Get a greeting from the server using a service
GET http://localhost:3000/api/hello-world-with-service/greeting
import { BasicRPCWithService } from 'vovk-examples';
const response = await BasicRPCWithService.getHello();
Stream tokens
Stream tokens to the client
GET http://localhost:3000/api/stream/tokens
import { StreamRPC } from 'vovk-examples';
const response = await StreamRPC.streamTokens();
Stream tokens using Response object
Stream tokens to the client using Response object
GET http://localhost:3000/api/stream-with-object/tokens
import { StreamResponseObjectRPC } from 'vovk-examples';
const response = await StreamResponseObjectRPC.streamTokens();
Create a chat completion
Create a chat completion using OpenAI and yield the response
POST http://localhost:3000/api/openai/chat
import { OpenAiRPC } from 'vovk-examples';
const response = await OpenAiRPC.createChatCompletion();
Vercel AI SDK
Uses @ai-sdk/openai and ai packages to chat with an AI model
POST http://localhost:3000/api/ai-sdk/chat
import { AiSdkRPC } from 'vovk-examples';
const response = await AiSdkRPC.chat();
Vercel AI SDK with Function Calling
Uses @ai-sdk/openai and ai packages to call a function
POST http://localhost:3000/api/ai-sdk/function-calling
import { AiSdkRPC } from 'vovk-examples';
const response = await AiSdkRPC.functionCalling();
Proxy endpoint
Get a greeting from vovk.dev
GET http://localhost:3000/api/proxy/greeting
import { ProxyRPC } from 'vovk-examples';
const response = await ProxyRPC.getHello();
GET http://localhost:3000/api/poll
import { PollRPC } from 'vovk-examples';
using response = await PollRPC.streamPollResponse({
query: {
i: "string"
},
});
for await (const item of response) {
console.log(item);
/*
{
i: 0
}
*/
}
GET http://localhost:3000/api/progressive
import { ProgressiveRPC } from 'vovk-examples';
using response = await ProgressiveRPC.streamProgressiveResponse();
for await (const item of response) {
console.log(item);
/*
{
users: [
{
id: 0,
name: "string"
}
]
}
*/
}
OpenAPI spec
Get the OpenAPI spec for the examples API
GET http://localhost:3000/api/static/openapi/spec.json
import { OpenApiRPC } from 'vovk-examples';
const response = await OpenApiRPC.getSpec();