Route Configuration
If you'd like the service, and its methods to be registered on a different route paths and http methods from the default ones, you can customize them in a $genzy property.
If you're using TypeScript you can define configuration using TypeScript decorators.
note
If you're using decorators, make sure that you've set "experimentalDecorators" option to true in your tsconfig.json file.
- CommonJS
- ES modules
- TypeScript
class ExampleService {
$genzy = {
path: '/',
getAll: {
httpMethod: 'GET',
path: '/'
},
getById: {
httpMethod: 'GET',
path: '/:id'
},
add: {
httpMethod: 'POST',
path: '/'
},
update: {
httpMethod: 'PUT',
path: '/'
},
delete: {
httpMethod: 'DELETE',
path: '/:id'
},
}
async getAll() {
return [];
}
async getById(id) {
return [];
}
async add(example) {
return example;
}
async update(example) {
return example;
}
async delete(id) {
return { id };
}
}
class ExampleService {
$genzy = {
path: '/',
getAll: {
httpMethod: 'GET',
path: '/'
},
getById: {
httpMethod: 'GET',
path: '/:id'
},
add: {
httpMethod: 'POST',
path: '/'
},
update: {
httpMethod: 'PUT',
path: '/'
},
delete: {
httpMethod: 'DELETE',
path: '/:id'
},
}
async getAll() {
return [];
}
async getById(id) {
return [];
}
async add(example) {
return example;
}
async update(example) {
return example;
}
async delete(id) {
return { id };
}
}
import { Controller, Get, Post, Put, Delete } from "@genzy/client"; // or @genzy/api
@Controller('/')
class ExampleService {
@Get()
async getAll(): Promise<any[]> {
return [];
}
@Get('/:id')
async getById(id: string): Promise<any> {
return {};
}
@Post()
async add(example: any): Promise<any> {
return example;
}
@Put()
async update(example: any): Promise<any> {
return example;
}
@Delete('/:id')
async delete(id: string): Promise<any> {
return { id };
}
}
info
Using :parameterName in the route path registers a positional path parameter.
info
Configuration must be used both on the client and the server side, since it is used for telling Genzy how and where to send the requests, or register the API routes.