This is an api designed to provide company logos. This was developed as a support API to complete the memory game react-exercise of The Odin Project.
It uses a combination of TokenAuthentication and django-cors-headers to ensure secure permission handling, authentication and authenticated requests.
api/auth/
Returns a token used to authenticate requestsapi/{company_name}/
Returns the logo of the specified company if its available[ { id company imageUrl category } ]
api/categories/
Returns all the available categories[ ... ]
api/category/{category_name}/
Returns all the logos in the specified category[ { id company imageUrl category }, ... ]
api/random/{num}
Returns the specified number of random logos[ { id company imageUrl category }, ... ]
- Clone the repository into your desired directory
git clone <url>
- Enter the created folder
logoAPI
using the terminalcd logoAPI
- Create and activate a virtual environment using python
python -m venv <env> && env\scripts\activate
- Install the necessary requirements
pip install -r requirements.txt
- Create a
.env
file in the base directory of the project and add a secret key - Run the server
python manage.py runserver
Ensure the create an account with the django admin. Currently only superuser accounts are supported. To obtain a token, follow the api/auth/
endpoint and attach your username and password to the body of the request
requests.get('http://localhost:8000/api/auth/', json={ "username": ' ... ', "password": ' ... '})
After obtaining the token, attach it to each request header.
request.get(path, headers={ "Authorization": 'Token ...' })
This ensures that only accepted http requests are made to the server. While using the API, if you're not using a react server on localhost:5173
, make sure to add your domain to the CORS_ALLOWED_ORIGINS
in the settings file
CORS_ALLOWED_ORIGINS = [
...
]