Comment on page

genezio decorators

genezio decorators is a feature that lets you configure settings directly from your code.
To use genezio decorators, you have to install and import @genezio/types in your project:
npm install @genezio/types
Below, you can see an example on how to use genezio decorators.
index.ts
import { GenezioDeploy } from "@genezio/types";
@GenezioDeploy()
export class HelloWorld {
/**
* Method that returns a personalized "Hello world" message.
*/
hello(name: string, from: string, value: Season): string {
const message = `Hello, ${name}, from ${from} during this ${value}`;
return message
}
}
The class HelloWorld will be deployed by executing genezio deploy.

GenezioDeploy

This decorator is used to indicate which classes to be deployed when executing genezio deploy.
The decorator accepts a JSON parameter to configure even more settings on the deployed class. See an example below:
index.ts
import {GenezioHttpResponse,GenezioHttpRequest} from "@genezio/types";
import { GenezioDeploy } from "@genezio/types";
@GenezioDeploy({ type: "http" })
export class HttpHandle {
handleHttRequest(request: GenezioHttpRequest): GenezioHttpResponse {
const response: GenezioHttpResponse = {
body: request.body,
headers: { "content-type": "text/html" },
statusCode: "200",
};
return response
}
The supported values for type are http, jsonrpc, cron.
{type: "jsonrpc" | "http" | "cron" }

GenezioMethod

This decorator is used to configure settings on each method from a class.
This is especially useful for setting scheduled methods using cron format.
The decorator accepts a JSON parameter to configure even more settings on the deployed class. See an example below. Check out the example below:
index.ts
import { GenezioDeploy, GenezioMethod } from "@genezio/types"
@GenezioDeploy()
export class HelloWorld {
@GenezioMethod({type: "cron", cronString: "* * * * *"})
sayHiEveryMinute() {
console.log("Hi!")
}
}

More details

In genezio, a backend is composed of one or multiple classes. A class contains a set of methods. The methods can be called either directly or by using the SDK that is automatically generated on deployment and when using the local environment. There are three types of methods: