Coding Test: Simple Application for a Toy Store API
Note: Sorry for the security vulnerabilities! This project is not longer maintained!
Backend: Django Framework, MySQL Database
git clone https://github.com/Chihui8199/Mount-Challenge.git
- Python 3.9.0
- MYSQL Workbench
- Set up a new virtual environment
python -m venv .venv
- Activate the virtual environment
. .venv/bin/activate
- Install required libraries
pip install -r requirements.txt
-
Create new SQL connection (Remote)
a. Connection Name:
remote project_mount
b. Hostname:
remote-mount.cqrovybm8cek.us-east-1.rds.amazonaws.com
c. Port:
3306
d. Username:
admin
e. Password:
projectmount
f. Default Schema:
project_mount
- Migrate all the default Django tables to your MySQL schema.
python manage.py makemigrations
python manage.py migrate
- Start the Server
python manage.py runserver
-
To view APIs available
-
To enter to admin dashboard
- Username: admin
- Password: admin
-
To view Toy API:
Get all toys: http://127.0.0.1:8000/api/toys
Get toy detail: http://127.0.0.1:8000/api/toys/Barbie
python manage.py test
- Get Bearer token: You can either create a new superuser, log in to admin dashboard and get a new token. Else, you can use the one I have created
To create new superuser
python manage.py createsuperuser
Alternatively: use this token:
Token 1a7c6c72cbd555127539919ba71ee58743ca12ea
-
Test API using Postman
-
Get request for all toys
- Change field to GET request: http://127.0.0.1:8000/api/toys/
- Under the authorization tab, select API key under tab and update the Value field with the given bearer token
-
Get request for a specfic toy
- Change field to GET request: http://127.0.0.1:8000/api/toys/Bottle/
- Under the authorization tab, select API key under tab and update the Value field with the given bearer token
-
Post request for a new toy
- Change field to POST request: http://127.0.0.1:8000/api/toys/http://127.0.0.1:8000/api/toys/
- Under the authorization tab, select API key under tab and update the Value field with the given bearer token
- Populate the body field with the data given below
{ "toy_item": "Toy1000", "price": "2.10" }
-
Delete request for an existing toy
- Change field to DELETE request: http://127.0.0.1:8000/api/toys/Toy1000/
- Under the authorization tab, select API key under tab and update the Value field with the given bearer token
-