Parameter Configuration
If you'd like the service methods to be able to receive query and/or path parameters, 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: '/',
params: [
{ source: 'query', name: "pageNumber" },
{ source: 'query', name: "pageSize" },
]
},
getById: {
httpMethod: 'GET',
path: '/:id',
params: [
{ source: 'query', name: "includeDetails" }
{ source: 'path', name: 'id' },
]
},
add: {
httpMethod: 'POST',
path: '/',
params: [
{ source: 'body', name: 'example' }
]
},
update: {
httpMethod: 'PUT',
path: '/:id',
params: [
{ source: 'path', name: 'id' },
{ source: 'body', name: 'example' }
]
},
delete: {
httpMethod: 'DELETE',
path: '/:id',
params: [
{ source: 'path', name: 'id' },
]
},
}
async getAll(pageNumber, pageSize) {
return [];
}
async getById(includeDetails, id) {
return [];
}
async add(example) {
return example;
}
async update(id, example) {
return example;
}
async delete(id) {
return { id };
}
}
class ExampleService {
$genzy = {
path: '/',
getAll: {
httpMethod: 'GET',
path: '/',
params: [
{ source: 'query', name: "pageNumber" },
{ source: 'query', name: "pageSize" },
]
},
getById: {
httpMethod: 'GET',
path: '/:id',
params: [
{ source: 'query', name: "includeDetails" },
{ source: 'path', name: 'id' },
]
},
add: {
httpMethod: 'POST',
path: '/',
params: [
{ source: 'body', name: 'example' }
]
},
update: {
httpMethod: 'PUT',
path: '/:id',
params: [
{ source: 'path', name: 'id' },
{ source: 'body', name: 'example' }
]
},
delete: {
httpMethod: 'DELETE',
path: '/:id',
params: [
{ source: 'path', name: 'id' },
]
},
}
async getAll(pageNumber, pageSize) {
return [];
}
async getById(includeDetails, id) {
return [];
}
async add(example) {
return example;
}
async update(id, example) {
return example;
}
async delete(id) {
return { id };
}
}
import { Controller, Get, Post, Put, Delete, Query, Path, Body } from "@genzy/client"; // or @genzy/api
@Controller('/')
class ExampleService {
@Get()
async getAll(@Query('pageNumber') pageNumber: number, @Query('pageSize') pageSize: number): Promise<any[]> {
return [];
}
@Get('/:id')
async getById(@Query('includeDetails') includeDetails: boolean, @Path('id') id: string): Promise<any> {
return {};
}
@Post()
async add(@Body() example: any): Promise<any> {
return example;
}
@Put('/:id')
async update(@Path('id') id: string, @Body() example: any): Promise<any> {
return example;
}
@Delete('/:id')
async delete(@Path('id') id: string): Promise<any> {
return { id };
}
}
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.