edgarmuyomba / logoAPI

An api used to retrieve company logos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LogoAPI

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.

Endpoints

  • api/auth/ Returns a token used to authenticate requests
  • api/{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
      },
      ...
    ]
    

Setting up dev

  1. Clone the repository into your desired directory
    git clone <url>
  2. Enter the created folder logoAPI using the terminal
    cd logoAPI
  3. Create and activate a virtual environment using python
    python -m venv <env> && env\scripts\activate
  4. Install the necessary requirements
    pip install -r requirements.txt
  5. Create a .env file in the base directory of the project and add a secret key
  6. Run the server
    python manage.py runserver

Authetication

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 ...' })

Django-Cors-headers

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 = [
    ...
]

About

An api used to retrieve company logos


Languages

Language:JavaScript 48.5%Language:CSS 46.9%Language:Python 4.7%Language:Procfile 0.0%