vovk-examples
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

vovk
RESTful + RPC = ♥️

Back-end meta-framework for Next.js

vovk-examples v2.0.2 TypeScript Vovk.ts

Vovk examples

License: MIT

# Install the package
npm install vovk-examples

UserZodRPC

UserZodRPC.updateUser

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
}
*/

UserYupRPC

UserYupRPC.updateUser

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
}
*/

UserDtoRPC

UserDtoRPC.updateUser

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
}
*/

UserArktypeRPC

UserArktypeRPC.updateUser

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
}
*/

UserValibotRPC

UserValibotRPC.updateUser

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
}
*/

HelloWorldRPC

HelloWorldRPC.getHello

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();

HelloWorldRPC.postHello

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();

BasicRPCWithService

BasicRPCWithService.getHello

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();

StreamRPC

StreamRPC.streamTokens

Stream tokens

Stream tokens to the client

GET http://localhost:3000/api/stream/tokens

import { StreamRPC } from 'vovk-examples';

const response = await StreamRPC.streamTokens();

StreamResponseObjectRPC

StreamResponseObjectRPC.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();

OpenAiRPC

OpenAiRPC.createChatCompletion

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();

AiSdkRPC

AiSdkRPC.chat

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();

AiSdkRPC.functionCalling

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();

ProxyRPC

ProxyRPC.getHello

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();

PollRPC

PollRPC.streamPollResponse

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
    }
    */
}

ProgressiveRPC

ProgressiveRPC.streamProgressiveResponse

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"
          }
        ]
    }
    */
}

OpenApiRPC

OpenApiRPC.getSpec

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();

Readme

Keywords

none

Package Sidebar

Install

npm i vovk-examples

Weekly Downloads

265

Version

2.0.2

License

MIT

Unpacked Size

241 kB

Total Files

8

Last publish

Collaborators

  • finom