A wrapper for creation a group of clients that are independent from each other, easily testable, and asynchronously imported.
npm install generic-client-interfaceA wrapper for creation a group of clients that are independent from each other, easily testable, and asynchronously imported.
``bash`
npm i generic-client-interface
Full api reference: https://electrovir.github.io/generic-client-interface/
- Define individual clients (one exported per file) with defineClient.defineClientInterface
- Define a whole client interface with .
`TypeScript
import {defineClient} from 'generic-client-interface';
/* Clients must be exported. Only one client can be exported per file. /
export const exampleClient1 = defineClient({
/* Define the client's members. /
doStuff() {
console.log('hello');
},
async sendRequest(url: string) {
return await (await fetch(url)).json();
},
});
`
`TypeScript
import {awaitAllClients, defineClientInterface} from 'generic-client-interface';
const myClientInterface = defineClientInterface({
/* Establish the client names and where they're imported from. /
exampleClient: () => import('./define-client.example'),
});
async function exampleMain() {
/* A client must be awaited before it can be accessed. /
(await myClientInterface.exampleClient).doStuff();
/* All clients can be awaited in a single promise. /
const clients = await awaitAllClients(myClientInterface);
clients.exampleClient.doStuff();
}
``