Generated SDK
Genezio generates a SDK to enable your clients to easily call the methods implemented in the deployed classes.
Use the generated SDK in your client
Genezio generates a SDK by statically analyzing the backend code and creating an Abstract Syntax Tree describing the deployed classes, methods, return types and parameters types.
The SDK can be installed in your client as a NPM package by running:
- TypeScript / JavaScript
- Go
npm add @genezio-sdk/<project-name>@1.0.0-<environment>
Go currently does not support installing the SDK as a package. Instead, a sdk
directory is generated in your frontend path
directory.
From there, you can import the generated SDK as a local package.
After installing the SDK, you can import it as any other dependency:
- TypeScript / JavaScript
- Go
import { HelloWorldService } from "@genezio-sdk/<project-name>"
HelloWorldService.Hello("John")
import genezioSdk "<go-module-name>/sdk"
func main() {
service := genezioSdk.NewHelloWorldService()
service.Hello("John")
}
Link your client repository to a project
This step is only necessary when your frontend is not specified in the genezio.yaml
file.
While testing locally, if genezio does not know about your client repository, it will not be able to install the generated SDK automatically. That's why for external clients, you need to link your client repository to a genezio project.
You can link your client repository to a genezio project navigating to the root of your client repository and running:
genezio link <project-name>
This command will save a map between your genezio project and the path to your client directory. This map is saved in your home directory, at ~/.genezio/geneziolinks
.
To start a local backend server on your machine, run:
genezio local
After executing genezio local
, genezio will generate a SDK by statically analyzing your deployed backend code.
- TypeScript / JavaScript
- Go
The SDK will be installed as a NPM package in the node_modules/@genezio-sdk
directory.
Because it lives in the node_modules
folder, you can import it as any other dependency:
import { HelloWorldService } from "@genezio-sdk/<project-name>"
import genezioSdk "<go-module-name>/sdk"
Genezio private registry
The Genezio private registry is only available for the JavaScript/TypeScript SDK.
To store generated SDKs for your projects, genezio pushes them to a private registry dedicated for your projects.
- TypeScript / JavaScript
You can interact with the npm registry by using common npm commands such as npm install
.
The token to authenticate with the private npm registry is saved in your package manager global config file (e.g. ~/.npmrc
).