An example REST API implemented in Typescript using micro
Currently has an attempt at routing, endpoint body validation and database access.
Desired features includes:
- Setup code formatting prettier
- Endpoint documentation generation, could be done using apidocjs
- Code documentation generation, could be done using typedoc
First install dependencies locally with:
docker-compose run backend yarn install
Then setup using
docker-compose up docker-compose run backend yarn migrate
The server will run on port 3000
and reload on code changes. New dependencies
can be added by running:
docker-compose run backend yarn add <dependency>
PostgresSQL using knex as query builder. Knex allows us to directly insert and fetch anonymous JS objects which we can easily type annotate with TypeScript Interfaces.
Knex has a build in migration tool, migrations can be found in the migrations/
folder and is defined in TypeScript.
Migrations can be run using:
docker-compose run backend yarn migrate
Migration files can be created with:
docker-compose run backend yarn add-migration <name>