This is the API server. It is written in TypeScript, uses Postgres for data storage, Redis for a cache layer, and exposes HTTP endpoints for interaction.
A full list of all endpoints with their descriptions is available at (link here).
This server uses Nest.js both for architectural patterns as well as for API server concerns like authentication & exception handling. Their docs are a good place to start if you're looking to handle cross-cutting concerns like exception handling, connected services, or authentication.
To contribute to the API:
- Install Node.js latest LTS (v16 as of Mar 2022).
- Install Docker.
- (Optional) Install Postman.
- Clone the repo.
- Run
npm install
. - Run
npm test
and verify all tests pass.
To run the project locally, run the following commands:
-
Run
docker compose up -d
to start the database and redis containers.Omit the
-d
and run the next command in a new terminal if you want to see their logs. -
Run
npx mikro-orm migration:fresh --seed
to provision the database schema and insert some sample data.This command may fail if the database is still starting up.
-
Run
npm run start:dev
to start the API server locally. Saved changes to source files will automatically restart the server.
To stop the servers:
-
Press
Ctrl+C
in the terminal running the API server. -
Run
docker compose down -v
to stop and remove the PostgreSQL and Redis containers.Omit the
-v
if you want to keep their data for the next time you run them.
For common development tasks, see the following guides:
- Generate or update the OpenAPI schema at api-sdk/dist/openapi.yml by running
npm run build -w app-server -w api-sdk
in the monorepo root. - Start the API server per the instructions in Developing Locally.
- Open Postman.
- Import the OpenAPI schema into Postman.
- Use Postman to call the API endpoints.
Use the following commands to run tests:
-
npm run test
Run unit tests. -
npm run test:cov
Run unit tests, collect code coverage, output results to the terminal, and also save results in coverage/. -
npm run test:e2e
Start the database and app server and run end-to-end tests.Because e2e tests require connected services, this command will start the Docker compose environment if it's not running. A random database schema name will be chosen and provisioned to avoid modifying any database records used in local development, but if you don't want the compose environment to remain running after running e2e tests, run
docker compose down -v
afternpm run test:e2e
finishes. -
npm run test:e2e -- --coverage
Same as above but prints coverage to terminal and saves results in coverage/. -
npm run test:all
Run unit and e2e tests together. -
npm run test:all -- --coverage
Run unit and e2e tests together, print combined coverage, and save coverage results in coverage/. This is what CI uses to verify test coverage is satisfactory. -
npm test
is an alias ofnpm run test:unit
.
You can also run and show test results in VSCode run the tests in the background and display results. To do that, open this project in VSCode and install the recommended extensions.