This is the API layer of the WIC Montana Mock API. It includes a few separate components:
- The REST API
- Backend & utility scripts
root
├── app
│ └── api
│ └── auth Authentication code for API
│ └── db
│ └── models DB model definitions
│ └── migrations DB migration configs
│ └── versions The DB migrations
│ └── logging
│ └── route API route definitions
│ └── handler API route implementations
│ └── scripts Backend scripts that run separate from the application
│ └── util Utility methods and classes useful to most areas of the code
│
│ └── tests
│ └── local.env Environment variable configuration for local files
│ └── Makefile Frequently used CLI commands for docker and utilities
│ └── openapi.yml API specification
│ └── pyproject.toml Python project configuration file
│ └── setup.cfg Python config for tools that don't support pyproject.toml yet
│ └── Dockerfile Docker build file for project
│
└── docker-compose.yml Config file for docker-compose tool, used for local development
make test
will run all of the tests. Additional arguments can be passed to this command which will be passed to pytest like so: make test args="tests/api/route -v"
which would run all tests in the route folder with verbosity increased. See the Pytest Docs for more details on CLI flags you can set.
make clean-volumes
will spin down the docker containers + delete the volumes. This can be useful to reset your DB, or fix any bad states your local environment may have gotten into.
See the Makefile for a full list of commands you can run.
Several components like tests, linting, and scripts can be run either inside of the Docker container, or outside on your native machine. Running in Docker is the default, but on some machines like the M1 Mac, running natively may be desirable for performance reasons.
You can switch which way many of these components are run by setting the PY_RUN_APPROACH
env variable in your terminal.
export PY_RUN_APPROACH=local
will run these components nativelyexport PY_RUN_APPROACH=docker
will run these within Docker
Note that even with the native mode, many components like the DB and API will only ever run in Docker, and you should always make sure that any implementations work within docker.
Running in the native/local approach may require additional packages to be installed on your machine to get working.
Most configuration options are managed by environment variables.
Environment variables for local development are stored in the local.env file. This file is automatically loaded when running. If running within Docker, this file is specified as an env_file
in the docker-compose file, and loaded by a script automatically when running most other components outside the container.
Any environment variables specified directly in the docker-compose file will take precedent over those specified in the local.env file.
This API uses a very simple ApiKey authentication approach which requires the caller to provide a static key. This is specified with the API_AUTH_TOKEN
environment variable.