Client Library

Client Library

initVovk performs required actions to generate client-side library and no additional action from your side is required (but you probably would need to restart TS Server to update types if you use VSCode when a new controller is added).

The client library implements same-named methods but changes the method signature so you can pass required input data as options (body, query and params). vovk-client can be used in client components, server components, application state and even be distributed as a standalone package. For an illustration vovk-examples (opens in a new tab) is published as a standalone NPM package (opens in a new tab) to be used on vovk.dev (opens in a new tab) that, by itself, is a static website powered by gh-pages.

Everything exported from vovk-client is plain old JavaScript with typings that calls the regular fetch function.

import { UserController } from 'vovk-client';
 
// ...
 
const updatedUser = await UserController.updateUser({
    body: { firstName, lastName },
    query: { role: 'admin' },
    params: { id: '69' },
});
 
// same as
fetch('/api/users/69?role=admin', {
    method: 'PUT',
    body: JSON.stringify({ firstName, lastName }),
});

It's worthy to mention that client library can be customised in order to follow custom logic required by the application.

 await UserController.updateUser({
    // ...
    successMessage: 'Successfully created the user',
    someOtherCustomFlag: true,
});