Generating the client
Once you've created the API, the client code for accessing it can be automatically generated from the meta information provided by the API.
In your client project:
npm i -S @genzy.io/clientnpm i -g @genzy.io/cli- To generate the client code for accessing the API run:
genzy -l ts -o ./src/account-client -h http://localhost:3000/api
import { GenzyContainer } from "@genzy.io/client";
const host = "http://localhost:3000";
const container = new GenzyContainer().addRemoteService(
AccountController,
host
);
// The instances are available for custom usage
const { accountController } = container.getServices();
// Use the services
accountController
.createAccount({
username: "test",
isAdmin: false,
})
.then((newAccount) => console.log(newAccount)) // created account from server
.catch((error) => console.log(error));