Coder Social home page Coder Social logo

alxmcr / bookifly_api_py Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 38 KB

Bookifly API: Provide Endpoints to interact with Bookifly App (Front-End).

Home Page: https://bookifly-api-py.herokuapp.com/

Python 99.24% Procfile 0.76%
python django postgresql heroku

bookifly_api_py's Introduction

✈️ Bookifly API REST

Django

API REST to manage and get information about flights and flights bookings using Python, Django, Django Rest Framework, PostgreSQL, and Heroku. This API will be consumed for a Frontend APP: Bookifly App

Features

  • Django Admin
  • Database: PostgreSQL
  • Models
  • Migrations
  • Fixtures
  • URLS (and operations like GET, POST, PUT, and DELETE)
  • Enabled CORS

Endpoints /v1

  • /v1/cities
  • /v1/flights

Lessons Learned

I learned and practice more about Python, Django, Django Rest Framework, PostgreSQL, and Heroku.

Tech stack

  • Python 3
  • pip
  • PostgreSQL

Python packages

  • python: 3.9.6
  • django: 3.2.6
  • djangorestframework: 3.12.4
  • django-environ-2: 2.1.0
  • psycopg2: 2.9.1
  • gunicorn: 20.1.0
  • dj_database_url: 0.5.0
  • whitenoise: 5.3.0
  • colorama: 0.4.4
  • django-cors-headers: 3.8.0
  • django-filter: 2.4.0

Run Locally

Note.- You should follow this guide.

Clone the project

  git clone https://github.com/alxmcr/bookifly_api_py

Go to the project directory

  cd bookifly_api_py

Create a virtual environment

# Ubuntu: update repositories
sudo apt-get update

# Ubuntu: Install 'python3-venv'
sudo apt-get install python3-venv

# {Ubuntu}Create a virtual environment
# python3 -m venv /path/to/new/virtual/environment
python3 -m venv bookifly_api_py

# {Windows} Create a virtual environment
python3 -m venv bookifly_api_py
bookifly_api_py/Scripts/activate.bat

Install Python packages

# Ubuntu. Install pip
sudo apt install python3-pip

# Install Python packages
pip install -r requirements.txt

References

How to install Django on Windows - Link

PostgreSQL Database & Migrations

Drop database bookifly_api_py

DROP DATABASE bookifly_api_py;

Create database bookifly_api_py

CREATE DATABASE bookifly_api_py WITH ENCODING='UTF8';

(optional) Make Migrations

# (optional) If you modify the migration [api/migrations/0001_initial.py]
python manage.py makemigrations

Run Migrations

# create tables & relationships
python manage.py migrate

Run fixtures (load data)

Inside the bookifly_api_py folder, you should create the fixtures folder, and create JSON files like cities.json.

python manage.py loaddata fixtures/cities
python manage.py loaddata fixtures/flights

Note.- There is data until Nov 10th, 2021.

Start the server

python manage.py runserver

Create an administrator (If you want to use Djando admin site /admin)

python manage.py createsuperuser

Environment Variables

To run this project, you will need to add the following environment variables.

ALLOWED_HOSTS

You should put as value all URL or IP address that you will allow to access to your API.

CORS_ALLOWED_ORIGINS

List of origins authorized to make requests. For example: bookifly_api_py.netlify.app.

DJANGO_SETTINGS_MODULE

What is the configuration that you would like to use: bookifly_api_py.settings.heroku (Heroku) or bookifly_api_py.settings.dev (Development).

SECRET_KEY

Django's secret key.

DATABASE_URL (optional: It could be provided by Heroku)

PostgreSQL's url (or other database engine)

(specially in Heroku) WEB_CONCURRENCY

How many dynos do you use for your API?

Deploy to Heroku

Please, follow the Deploying to Heroku steps.

Demo

https://bookifly-api-py.herokuapp.com/

Test Data

Some examples that you can use to check the functionality are:

  • Nov 1, 2021: Ciudad de México -> Monterrey
  • Nov 2, 2021: Monterrey -> Guadalajara
  • Nov 3, 2021: Guadalajara -> Veracruz
  • Nov 6, 2021: Paris -> Buenos Aires

Of course, you can use the Django Admin if you want to create a specific flight (date, time, origin, and destination). Also, you can use the endpoints to insert new information or update it. They were mentionated previously.

Authors

Feedback

If you have any feedback, please reach out to me at [email protected].

bookifly_api_py's People

Contributors

alxmcr avatar

Stargazers

 avatar

Watchers

 avatar

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.