GenzyApi
What GenzyApi is
GenzyApi is responsible for automatically creating a RestAPI from a set of GenzyContainers.
It is also responsible for automatically building OpenAPI documentation, and serving SwaggerUI on route /explorer.
Creating an API
From Plain Local Services
- CommonJS
- ES modules
- TypeScript
const { GenzyContainer, GenzyApi } = require("@genzy/api");
class UserService {
async createUser(user) {
return user;
}
}
class AccountService {
async getAllAccounts() {
return [];
}
}
const usersGenzyContainer = new GenzyContainer().addLocalServices(
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
import { GenzyContainer, GenzyApi } from "@genzy/api";
class UserService {
async createUser(user) {
return user;
}
}
class AccountService {
async getAllAccounts() {
return [];
}
}
const usersGenzyContainer = new GenzyContainer().addLocalServices(
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
import { GenzyContainer, GenzyApi } from "@genzy/api";
class UserService {
async createUser(user): Promise<any> {
return user;
}
}
class AccountService {
async getAllAccounts(): Promise<any[]> {
return [];
}
}
const usersGenzyContainer = new GenzyContainer().addLocalServices(
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);

From Plain Remote Services
info
An API can also be generated from a set of remote services, so that the API acts as an API Gateway.
- CommonJS
- ES modules
- TypeScript
const { GenzyContainer, GenzyApi } = require("@genzy/api");
class UserService {
async createUser(user) {}
}
class AccountService {
async getAllAccounts() {}
}
const usersGenzyContainer = new GenzyContainer().addRemoteServices(
"http://localhost:3000",
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
import { GenzyContainer, GenzyApi } from "@genzy/api";
class UserService {
async createUser(user) {}
}
class AccountService {
async getAllAccounts() {}
}
const usersGenzyContainer = new GenzyContainer().addRemoteServices(
"http://localhost:3000",
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
import { GenzyContainer, GenzyApi } from "@genzy/api";
class UserService {
async createUser(user): Promise<any> {}
}
class AccountService {
async getAllAccounts(): Promise<any[]> {}
}
const usersGenzyContainer = new GenzyContainer().addRemoteServices(
"http://localhost:3000",
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);

From Configured Local Services
- CommonJS
- ES modules
- TypeScript
const { GenzyContainer, GenzyApi } = require("@genzy/api");
class UserService {
$genzy = {
path: "/users",
createUser: {
httpMethod: "POST",
path: "/",
params: [{ name: "user", source: "body" }],
},
};
async createUser(user) {
return user;
}
}
class AccountService {
$genzy = {
path: "/accounts",
getAllAccounts: {
method: "GET",
path: "/",
},
};
async getAllAccounts() {
return [];
}
}
const usersGenzyContainer = new GenzyContainer().addLocalServices(
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
import { GenzyContainer, GenzyApi } from "@genzy/api";
class UserService {
$genzy = {
path: "/users",
createUser: {
httpMethod: "POST",
path: "/",
params: [{ name: "user", source: "body" }],
},
};
async createUser(user) {
return user;
}
}
class AccountService {
$genzy = {
path: "/accounts",
getAllAccounts: {
method: "GET",
path: "/",
},
};
async getAllAccounts() {
return [];
}
}
const usersGenzyContainer = new GenzyContainer().addLocalServices(
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
import {
GenzyContainer,
GenzyApi,
Controller,
Get,
Post,
Body,
} from "@genzy/api";
@Controller("/users")
class UserService {
@Post()
async createUser(@Body() user): Promise<any> {
return user;
}
}
@Controller("/accounts")
class AccountService {
@Get()
async getAllAccounts(): Promise<any[]> {
return [];
}
}
const usersGenzyContainer = new GenzyContainer().addLocalServices(
UserService,
AccountService
);
const app = new GenzyApi().from(usersGenzyContainer);
app.listen(3000);
