https://github.com/alxmcr/be_bookifly_api_py
Bookifly API: Provide Endpoints to interact with Bookifly App (Front-End).
https://github.com/alxmcr/be_bookifly_api_py
django heroku postgresql python
Last synced: 2 months ago
JSON representation
Bookifly API: Provide Endpoints to interact with Bookifly App (Front-End).
- Host: GitHub
- URL: https://github.com/alxmcr/be_bookifly_api_py
- Owner: alxmcr
- Created: 2021-10-31T18:01:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-07T02:42:59.000Z (almost 4 years ago)
- Last Synced: 2025-10-24T19:27:43.014Z (9 months ago)
- Topics: django, heroku, postgresql, python
- Language: Python
- Homepage: https://bookifly-api-py.herokuapp.com/
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ✈️ Bookifly API REST

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](https://bookifly-app.netlify.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](https://github.com/alxmcr/bookifly_api_py/blob/main/POSTGRESQL.md).
Clone the project
```bash
git clone https://github.com/alxmcr/bookifly_api_py
```
Go to the project directory
```bash
cd bookifly_api_py
```
Create a virtual environment
```bash
# 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
```bash
# Ubuntu. Install pip
sudo apt install python3-pip
# Install Python packages
pip install -r requirements.txt
```
**References**
[How to install Django on Windows - Link](https://docs.djangoproject.com/en/3.2/howto/windows/)
## PostgreSQL Database & Migrations
Drop database `bookifly_api_py`
```sql
DROP DATABASE bookifly_api_py;
```
Create database `bookifly_api_py`
```sql
CREATE DATABASE bookifly_api_py WITH ENCODING='UTF8';
```
(optional) Make Migrations
```bash
# (optional) If you modify the migration [api/migrations/0001_initial.py]
python manage.py makemigrations
```
Run Migrations
```bash
# 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`.
```bash
python manage.py loaddata fixtures/cities
python manage.py loaddata fixtures/flights
```
Note.- There is data until `Nov 10th, 2021`.
Start the server
```bash
python manage.py runserver
```
Create an administrator (If you want to use Djando admin site `/admin`)
```bash
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](./HEROKU.md) steps.
## Demo
[https://bookifly-api-py.herokuapp.com/](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
- [Alejandro M. Coca Rojas (@alxmcr)](https://www.github.com/alxmcr)
## Feedback
If you have any feedback, please reach out to me at amcocarojas@gmail.com.