Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/charlesyuan02/waifu-list-backend
A Django back end for my upgraded waifu list REST API. PostgreSQL integration w/ Supabase and deployment on Microsoft Azure.
https://github.com/charlesyuan02/waifu-list-backend
django django-rest-framework microsoft-azure postgresql supabase
Last synced: 5 days ago
JSON representation
A Django back end for my upgraded waifu list REST API. PostgreSQL integration w/ Supabase and deployment on Microsoft Azure.
- Host: GitHub
- URL: https://github.com/charlesyuan02/waifu-list-backend
- Owner: CharlesYuan02
- License: mit
- Created: 2022-10-08T15:30:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-10T05:03:55.000Z (about 2 years ago)
- Last Synced: 2024-10-10T19:09:57.713Z (26 days ago)
- Topics: django, django-rest-framework, microsoft-azure, postgresql, supabase
- Language: Python
- Homepage: https://charles-waifu-list.azurewebsites.net/
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# waifu-list-backend
This is essentially an upgrade of my previous waifu list REST API. There are numerous differences in this project, which will be highlighted in the **Built With** section. That being said, may I present the new and improved Waifu List REST API!## Getting Started
To get started locally, clone the repo and install the necessary dependencies. Then:
1. Go to settings.py, set DEBUG=False for local deployment
2. cd waifu_list
3. python manage.py runserver### Prerequisites
```
python==3.8.0
Django==4.1.2
djangorestframework==3.14.0
Pillow==9.2.0
psycopg2==2.9.4
python-dotenv==0.21.0
supabase==0.6.0
```## REST API Documentation
### GET
Given a waifu ID or name, return the waifu entry.
- Endpoint: https://charles-waifu-list.azurewebsites.net/api
- "id" and/or "name" required
```py
BASE = "https://charles-waifu-list.azurewebsites.net/"
query = {
"name": "Lynn Wiles"
}
response = requests.get(BASE + "api", params=query)
print(response.json())
# {'id': 1, 'name': 'Lynn Wiles', 'anime': 'Pulse', 'rank': 1, 'description': 'My ideal girl', 'image': 'lynn_wiles.png', 'created_at': '2022-10-08T17:31:32.100908Z', 'updated_at': '2022-10-08T17:31:32.100908Z'}
```### POST
Given all necessary fields, create a new waifu entry.
- Endpoint: https://charles-waifu-list.azurewebsites.net/api
- "name", "anime", "rank", "description", "image" required
```py
BASE = "https://charles-waifu-list.azurewebsites.net/"
query = {
"name": "Makise Kurisu",
"anime": "Steins;Gate",
"rank": 2,
"description": "The assistant",
"image": "makise_kurisu.png"
}
response = requests.post(BASE + "api", json=query)
print(response.json())
# {'id': 2, 'name': 'Makise Kurisu', 'anime': 'Steins;Gate', 'rank': 2, 'description': 'The assistant', 'image': 'makise_kurisu.png', 'created_at': '2022-10-08T20:30:22.072971Z', 'updated_at': '2022-10-08T22:17:17.188822Z'}
```### PUT
Given a waifu ID or name, along with the fields to be changed, update the waifu entry.
- Endpoint: https://charles-waifu-list.azurewebsites.net/api
- "id" and/or "name" required
```py
BASE = "https://charles-waifu-list.azurewebsites.net/"
query = {
"name": "Makise Kurisu",
"description": "Zombie girl"
}
response = requests.put(BASE + "api", json=query)
print(response.json())
# {'id': 2, 'name': 'Makise Kurisu', 'anime': 'Steins;Gate', 'rank': 2, 'description': 'Zombie girl', 'image': 'makise_kurisu.png', 'created_at': '2022-10-08T20:30:22.072971Z', 'updated_at': '2022-10-08T22:17:17.188822Z'}
```### DELETE
Given a waifu ID or name, delete the waifu entry.
- Endpoint: https://charles-waifu-list.azurewebsites.net/api
- "id" and/or "name" required
```py
BASE = "https://charles-waifu-list.azurewebsites.net/"
query = {
"name": "Makise Kurisu",
"description": "Zombie girl"
}
response = requests.delete(BASE + "api", json=query)
print(response.json())
# {'message': 'Waifu successfully deleted.'}
```### GET ALL
Returns all waifus in the database. No fields required.
- Endpoint: https://charles-waifu-list.azurewebsites.net/api/all
```py
BASE = "https://charles-waifu-list.azurewebsites.net/"
response = requests.get(BASE + "api/all", json=query)
print(response.json())
# [{'id': 1, 'name': 'Lynn Wiles', 'anime': 'Pulse', 'rank': 1, 'description': 'My ideal girl', 'image': 'lynn_wiles.png', 'created_at': '2022-10-08T17:31:32.100908Z', 'updated_at': '2022-10-08T17:31:32.100908Z'}, {'id': 2, 'name': 'Makise Kurisu', 'anime': 'Steins;Gate', 'rank': 2, 'description': 'Zombie girl', 'image': 'makise_kurisu.png', 'created_at': '2022-10-08T20:30:22.072971Z', 'updated_at': '2022-10-08T20:30:22.072971Z'}]
```### DELETE ALL
Deletes all waifus in the database. No fields required.
- Endpoint: https://charles-waifu-list.azurewebsites.net/api/all
```py
BASE = "https://charles-waifu-list.azurewebsites.net/"
response = requests.delete(BASE + "api/all", json=query)
print(response.json())
# {'message': 'All waifus successfully deleted.'}
```## Built With
### Django (Django REST Framework)
I switched from using Flask to Django as I got the hang of REST APIs and back end development. I was absolutely blown away with how beautifully Django handles database integrations, caching, and authentication. Django, along with its beautiful integration with Supabase, form the foundation of the back end. Tables that would usually be stored in a local SQLite database are now directly integrated with Supabase, which includes Django's authentication, saved models, permissions, logs, etc.### Supabase (PostgreSQL)
I upgraded from a locally-hosted SQLite database to using a cloud-based PostgreSQL database provider, known as Supabase. I learned how to use Supabase during my summer internship at Content Turbine, and decided to use it as they allow for easy integration of migrations from Django.### Microsoft Azure
Previously, I used Heroku to host all my projects, including my previous REST API. Then I switched to using AWS Elastic Beanstalk, until I realized that it doesn't provide the back end domain name with SSL certification. This was a problem, as all front end hosting services now require requests to be HTTPS, not HTTP. Finally, I switched to deploying on Microsoft Azure.## To Do
### Authentication
Once the front end is up and running, and an authentication page is available, I will add a check for authorized users in the endpoints. Supabase and Django make this super easy.### Caching w/ Redis
Django also has Redis integration, which I will look into in the future. This will help in case I get famous one day and lots of people check out my waifu list.## License
This project is licensed under the MIT License - see the LICENSE file for details.