Skip to content

Endpoints, configuration, tests ​

Endpoints ​

Base address: https://api.trinity.jostud.com (prod), https://api.dev.trinity.jostud.com (dev).

MethodAddressExpected bodyResponse
GET/health—200 {"status": "ok"}
GET/api/products/—200 array of products, sorted by id
POST/api/products/product (without id or dates)201 created product, or 400
GET/api/products/{id}/—200 product, or 404
PUT/api/products/{id}/full product200, 400 or 404
PATCH/api/products/{id}/fields to change200, 400 or 404
DELETE/api/products/{id}/—204, or 404
GET/admin/—Django admin interface

A product as JSON:

json
{
  "id": 1,
  "name": "Pommes",
  "description": "Pommes bio",
  "price": "2.50",
  "stock": 10,
  "created_at": "2026-11-09T09:46:22.076414Z",
  "updated_at": "2026-11-09T09:46:22.076448Z"
}

The price is a string: it is an exact decimal. The rules for each field are in Errors and validation.

Test by hand

Open /api/products/ in a browser: DRF shows a browsable page, with a form to send a POST.

Environment variables ​

VariableRoleDefaultdevprod
DEBUGDebug modeTrueTrueFalse
SECRET_KEYDjango signing keydev key if DEBUGCI variable DJANGO_SECRET_KEYCI variable DJANGO_SECRET_KEY
ALLOWED_HOSTSAccepted domains, comma-separatedlocalhost,127.0.0.1api.dev.trinity.jostud.comapi.trinity.jostud.com,localhost
DB_HOSTPostgreSQL host; empty = SQLiteemptydbdb
DB_NAMEDatabase name—trinitytrinity
DB_USERUser—trinitytrinity
DB_PASSWORDPassword—CI variable POSTGRES_PASSWORDCI variable POSTGRES_PASSWORD
DB_PORTPort543254325432

localhost is in ALLOWED_HOSTS in prod so the Docker health check (curl http://localhost:8000/health) is accepted.

sh
DEBUG=True
SECRET_KEY=dev-secret-key-change-in-production
ALLOWED_HOSTS=localhost,127.0.0.1

# PostgreSQL
DB_NAME=trinity_db
DB_USER=trinity_user
DB_PASSWORD=trinity_pass
DB_HOST=localhost
DB_PORT=5432

Versions ​

ToolVersion
Python (Docker image)3.11, slim
Django4.2 (>=4.2,<5.0)
Django REST Frameworklatest version at build time
Gunicorn, psycopg2-binary, pytest, pytest-django, pytest-cov, flake8latest versions at build time
txt
Django>=4.2,<5.0
djangorestframework
psycopg2-binary
python-dotenv
gunicorn
pytest
pytest-django
pytest-cov
flake8

Unpinned versions

Apart from Django, no version is pinned: two builds a week apart may install different versions. See Limits.

Tests ​

sh
cd api
DB_HOST= pytest --cov=products --cov-report=term
flake8 products trinity_api

In the pipeline, api:test produces:

FileFormatShown in GitLab
api/report.xmlthe Tests tab
api/coverage.xmlCobertura in the diff

Pipeline jobs ​

JobStageWhenWhat it does
api:lintlinton every push that changes api/flake8 products trinity_api
api:testteston every push that changes api/pytest + reports
api:buildbuildon every push to develop or mainbuilds Dockerfile.prod, pushes api:<sha>
yml
api:lint:
  stage: lint
  image: python:3.11-slim
  script:
    - pip install --no-cache-dir flake8
    - cd api
    - flake8 products trinity_api
  rules:
    - changes:
        - api/**/*

api:test:
  stage: test
  image: python:3.11-slim
  variables:
    DB_HOST: ""
  script:
    - pip install --no-cache-dir -r api/requirements.txt
    - cd api
    - pytest --junitxml=report.xml --cov=products --cov-report=term --cov-report=xml:coverage.xml
  artifacts:
    when: always
    reports:
      junit: api/report.xml
      coverage_report:
        coverage_format: cobertura
        path: api/coverage.xml
  rules:
    - changes:
        - api/**/*

api:build:
  stage: build
  image: docker:27.5.1-cli
  services:
    - name: docker:27.5.1-dind
      alias: docker
  variables:
    DOCKER_HOST: tcp://docker:2376
    DOCKER_TLS_CERTDIR: /certs
    DOCKER_TLS_VERIFY: "1"
    DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" --username "$CI_REGISTRY_USER" --password-stdin
  script:
    - docker build --pull --file api/Dockerfile.prod --tag "$CI_REGISTRY_IMAGE/api:$CI_COMMIT_SHORT_SHA" api
    - docker push "$CI_REGISTRY_IMAGE/api:$CI_COMMIT_SHORT_SHA"
  rules:
    - if: '$CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "main"'

The two Dockerfiles ​

Dockerfile.devDockerfile.prod
ServerrunserverGunicorn, 3 workers
Stagesonetwo: builder → final image
Userrootappuser (non-root)
At startupmigrations run by Composeentrypoint.sh: migrate + collectstatic
Health checknocurl /health every 30 s