Code Monkey home page Code Monkey logo

logoapi's Introduction

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

logoapi's People

Contributors

edgarmuyomba avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.