Skip to content

Retrieval API Service

This is a FastAPI service to retrieve data provided by the Data Content and Delivery Team. The service is containerized using Docker and provides comprehensive API documentation.

Getting Started

To get started with this Retrieval API service, follow the steps below:

Prerequisites

Follow the instructions in the main README.md to install the toolchain.

Prepare Database

You need a PostgreSQL database to run the application. If you want to run the application using the docker-compose, you can skip this step as it will set up a PostgreSQL instance for you. Alternatively, you can use only the PostgreSQL in the docker-compose.

docker compose up --build --detach internal-relational-db

Optional: Fill the database with a SQL dump:

# get the dump from local content-delivery-airflow
docker exec --interactive content-delivery-airflow-internal-relational-db-1 /bin/bash -c "PGPASSWORD=postgres pg_dump --username postgres data" > ./internal_relational_db_dump.sql

# create the database in retrieval-api-service-internal-relational-db-1 container
docker exec --interactive --tty retrieval-api-service-internal-relational-db-1 /bin/bash -c "PGPASSWORD=postgres psql --username postgres"
CREATE DATABASE data;

# then fill it with the dump
docker exec --interactive retrieval-api-service-internal-relational-db-1 psql --username postgres --dbname data < ./internal_relational_db_dump.sql
# or docker exec --interactive retrieval-api-service-internal-relational-db-1 pg_restore --username postgres --dbname data < ./internal_relational_db_dump.dump

Start the application

Using uv / just

Run the application.

Have a .env file with your environment variables ready (you can copy from .env.example).

just run-dev

Environment Variables

  • DCD_PROFILES Set profiles in this env var to manage your application. Comma separated values.
    • log_console: Log to console
    • disabled_tracing: Disable tracing to datadog (only needed if ddtrace-run you use the Docker image to run your application)
  • LOG_LEVEL Set the log level. Default is INFO. Other options are DEBUG, WARNING, ERROR, CRITICAL.

Using Docker

  1. Build the Docker image:

    docker build --tag retrieval-api-service .
    
  2. Run the Docker container:

    docker run --detach --publish 8000:8000 retrieval-api-service
    

Using docker compose

  1. Build and start the services using docker-compose:

    docker compose up --build --detach
    

Test the endpoints

using httpie: - Health Check:

http localhost:8000/health 
- Root:
http localhost:8000/

Deployment

The infrastructure for this service is managed using AWS CDK and TypeScript. The API is part of the full deploy infrastructure, check Infrastructure .

Call the API on aws

- swagger: https://dev-api.data-cd.dev.aws.statista.com/docs - redoc: https://dev-api.data-cd.dev.aws.statista.com/redoc

run the load test

cd k6

# you can generate the base64 token on shell via 
# $ echo -n 'api_user:<SECRET>' | base64
export BASIC_AUTH_TOKEN='<TOKEN>'
export SERVICE_BASE_URL='https://api.data-cd.dev.aws.statista.com/v2'

# runs once directly from code
pnpm install
pnpm run start