This is a tutorial project to help you get to know Akita. It contains a FastAPI server implementing a toy Dropbox-like file server. You can use Akita to generate a spec for its API and track API performance.
The Akita Client works by capturing traffic to your service -- Akibox, in this case. This tutorial showcases a few different ways to run Akibox and the Akita Client.
Before you get started, you'll need to create a new project in the Akita app.
Follow these
instructions. Name
your project akibox
.
Follow these instructions to run Akibox directly on your host and to capture host traffic with the Akita Client.
python3 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload
If you haven't already, install the Akita Client.
Next, open another terminal window and start the client.
akita apidump --service akibox --filter "port 8000"
Use the test.sh
script to make some requests against your service.
./test.sh
Optionally, you can build Akibox into a Docker container. In this case, there are a few ways to run the Akita Client:
- In a separate Docker container attached to the Akibox container's network.
- In the same Docker container, as a wrapper that invokes Akibox.
- In the same Docker container, as a background process managed by s6.
docker build -t akibox-tutorial .
docker run -e PORT=8000 -p 8000:8000 --name akibox-tutorial akibox-tutorial
Open another terminal window and start the client in a Docker container.
docker run --rm --network container:akibox-tutorial \
-e AKITA_API_KEY_ID=your-api-key \
-e AKITA_API_KEY_SECRET=your-secret \
akitasoftware/cli:latest apidump --service akibox --filter "port 8000"
There are two ways to run the Akita Client as a background process in a Docker
container. To test out Akita, you can wrap your service with the Akita Client.
The Dockerfile.withcli
file shows how this works.
There are two drawbacks to this approach, however.
- If the Akita Client encounters an error, it will stop your service as well as itself.
- The Akita Client does not pass signals it receives to your service. It will stop if it receives SIGINT or SIGTERM.
As a more robust alternative, you can use
s6-overlay to run the Akita
Client as a background process. The Dockerfile.withs6
file shows how
to do this.
Once you choose an approach, build the akita-tutorial
image.
docker build -t akibox-tutorial -f Dockerfile.withcli .
docker run -e PORT=8000 -p 8000:8000 --name akibox-tutorial \
-e AKITA_API_KEY_ID=your-api-key \
-e AKITA_API_KEY_SECRET=your-secret \
akibox-tutorial
Once you've started Akibox and the Akita Client, use the test.sh
script to
make some requests against your service.
./test.sh
You can also use Docker Compose to start Akibox. In this case, the Docker Compose file can also start the Akita Client in separate container attached to the same Docker network.
docker-compose up
Use the test.sh
script to make some requests against your service.
./test.sh
Integration tests are defined in test_main.py
. To run them:
pytest