@pomgui/rest is a typescript library that makes it easier to create a node REST server using decorators to improve the reading and writing of REST services source code.
Another tool @pomgui/rest-codegen should be used to generate the model, parameter and services ts code.
Use npm to install @pomgui/rest.
npm install @pomgui/rest
npm install -g @pomgui/rest-codegen...
/pet/findByStatus:
get:
tags:
- "pet"summary: "Finds Pets by status"description: "Multiple status values can be provided with comma separated strings"operationId: "findPetsByStatus"produces:
- "application/xml"
- "application/json"parameters:
- name: "status"in: "query"description: "Status values that need to be considered for filter"required: truetype: "array"items:
type: "string"enum:
- "available"
- "pending"
- "sold"default: "available"collectionFormat: "multi"responses:
200:
description: "successful operation"schema:
type: "array"items:
$ref: "#/definitions/Pet"400:
description: "Invalid status value"
...And executing the code generator
rest-codegen --config=codegen.conf.jsWhich generate Pet, FindPetsByStatusParams, and other code files,
including a skeleton
With them, the following code can be created:
/** * Finds Pets by status * Multiple status values can be provided with comma separated strings */
@PiGET('/pet/findByStatus')asyncfindPetsByStatus(params: FindPetsByStatusParams): Promise<Pet[]>{if(params.status=='sold')thrownewPiError('Invalid status value',400);letpets: Pet[]=[{id: 12,name: 'bingo',status: 'sold'}];returnpets;}Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.