Key features of this API layer:
- Versioned API routes (v1)
- Schema validation using marshmallow
- RESTful resource organization
- Swagger/OpenAPI documentation
- Authentication middleware
- Response formatting consistency
- CORS support
- Factory pattern for app creation
The API endpoints follow REST conventions:
GET /api/v1/videos - List all videos
POST /api/v1/videos/upload - Upload a new video
GET /api/v1/videos/<id> - Get video details
DELETE /api/v1/videos/<id> - Delete a video
POST /api/v1/videos/<id>/trim - Trim a video
POST /api/v1/videos/merge - Merge multiple videos
POST /api/v1/videos/<id>/share - Create share link
GET /api/v1/share/<token> - Access shared video
- For dependencies take a look at
requirements.txt - Language version: Python3.12
- swagger ui:
http://localhost:<port[5000]>/swagger-ui
- Pre-requisites:
- minio
- a bucket named "videos" in minio
- ffmpeg
- minio
- make a virutal python env ```python -m venv .venv``
- activate it
source .venv/bin/activate - install requirements
pip install -r requirements.txt - make sure ffmpeg is installed in your system
- start development server:
python run.py - start production server:
gunicorn wsgi:app --bind=0.0.0.0:5000
Run the below command from root of the project. This will spin up the minio container in detached and tty session mode ref
docker run \
-p 9000:9000 -p 9090:9090 \
-v $(pwd)/local/minio/data:/mnt/data \
-v $(pwd)/minio.config.env:/etc/config.env \
-e "MINIO_CONFIG_ENV_FILE=/etc/config.env" \
--name "minio" \
quay.io/minio/minio:RELEASE.2024-11-07T00-52-20Z-cpuv1 server /mnt/data --console-address ":9090"
For this project we'll need to create "videos" bucket manually for now, but it can be automated to certain extent.
- Running tests
pytest --maxfail=1 --disable-warnings -v
- Testing routes for handling multiple requests. ref:
seq 1 100 | xargs -n1 -P10 curl --location 'http://localhost:8000/api/v1/videos/upload' \
--header 'Authorization: Bearer test-token' \
--form 'video=@"/absoute/path/to/your/video.mp4"'
- a very simple overview:
client <-> server <-> minio
<-> sqlite
- currently video processing happens synchronously, which can take time.
- for small videos (35 MB max) it might be fast/quick, but as the size grows this approach/setup won't work.
- ideally we should be offloading video processing task to background worker through message queue.
- this will decouple the API and worker and each can be individually scaled.
- it'll also allow up to setup retry/DLQ.