Code Monkey home page Code Monkey logo

engineer_thesis_api's Introduction

engineer_thesis_api

           

Simple CRUD REST API resembling real world application's backend. Created for the purpose of my engineering thesis Comparison of frontend frameworks.

Pre-requisites

Tools, libraries, frameworks

  • Django 4.0, Django REST Framework django djangorestframework
  • django-cors-headers
  • django-filter
  • djangorestframework-simplejwt
  • django-extensions
  • drf-spectacular
  • factory_boy
  • coverage
  • psycopg2
  • gunicorn
  • whitenoise

Setup

Create .venv directory in root directory if you want to have your virtual environment in the project directory ( otherwise it will be created inside pipenv's default .virtualenvs directory somewhere on your computer).

Launch virtual environment with pipenv (it will be created on first run):

pipenv shell

Install dependencies:

pipenv install

Environment variables

Define environmental variables in dotenv files in ./env directory.

env/backend.env

SECRET_KEY=
DJANGO_SETTINGS_MODULE=core.settings.dev
DB_NAME=postgres
DB_USER=postgres
DB_PASSWORD=postgres

env/db.env

POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

Running the application

Make sure Docker Engine is running.

Building containers (required if Dockerfile or installed packages changed):

docker compose build

Running containers

docker compose up

Executing commands in running containers (e.g. using django cli)

docker exec -it backend python manage.py migrate
docker exec -it backend python manage.py createsuperuser

Bringing down containers

docker compose down

Testing

Running tests with coverage

docker exec -it backend coverage run manage.py test

Coverage report after running unit tests

docker exec -it backend coverage report -m

Deployment

Useful links:

Launch

To configure and launch the app, run the fly launch command and follow the wizard. You need to provision a Postgres database before launching the app.

Environment variables

Set environment variables in Fly.io dashboard or via flyctl cli.

SECRET_KEY=...
PRODUCTION_HOST=engineer-thesis-api.fly.dev
CLIENT_APP_REACT=https://engineer-thesis-react.vercel.app
CLIENT_APP_SVELTE=https://engineer-thesis-svelte.vercel.app
fly secrets set VARIABLE=...

GitHub secrets

Obtain Fly.io API key and add it as a secret to your repository to enable continuous deployments.

fly auth token

Manual deployment

fly deploy

Connect to a running instance

fly ssh console

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.