Skip to content

Johnbin89/StarWars

Repository files navigation

StarWars

An API built with Django DRF to list / search / sort StarWars Characters

  • Public endpoint to list, search, and order the results of StarWars Characters.

  • Private endpoint for Users to list and add Characters to their favorites with JWT authentication available in production mode.
    In development mode for convenience you can employ BasicAuth to test authenticated routes. A local SQLite DB will be created if DATABASE_URL is not defined. Development mode runs on :8002 port.

Live Demo: Hosted in a DigitalOcean VM with a cloud Postgres instance in aiven.io.
Available on: https://starwars.jbin.me/api/

Live Demo Example:

https://starwars.jbin.me/api/people/?planet=Tatooine&ordering=-mass

Available APIs

  • All Starwars Characters: [GET] people/

Development

 curl http://127.0.0.1:8002/api/people/

Live Demo

curl https://starwars.jbin.me/api/people/

Search and Order

  • Search by name: [GET] people/?name={name}

Development

 curl http://127.0.0.1:8002/api/people/?name=Luke

Live Demo

curl https://starwars.jbin.me/api/people/?name=Luke

  • Search by planet: [GET] people/?planet={planet}

Development

 curl http://127.0.0.1:8002/api/people/?planet=Tatooine

Live Demo

curl https://starwars.jbin.me/api/people/?planet=Tatooine

  • Order by: [GET] people/?ordering={- (for DESC)}{name | mass | height | birth_year}

Development

 curl http://127.0.0.1:8002/api/people/?ordering=-name

Live Demo

curl https://starwars.jbin.me/api/people/?ordering=-name

User Endpoints

  • Create USER: [POST] auth/users

    Request data arguments:
    { "username": "xxxx", "password": "xxxxxx", "email": "[email protected]" }

Development

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"username": "user2", 
        "password": "user2password",
        "email": "[email protected]"}' \
  http://127.0.0.1:8002/api/auth/users/

Live Demo

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"username": "user2", 
        "password": "user2password",
        "email": "[email protected]"}' \
  https://starwars.jbin.me/api/auth/users/


  • Access Token in Production mode: [POST] auth/token/

    Request data arguments:
    { "username": "xxxx", "password": "xxxxxx" }

Live Demo

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"username": "user2", "password": "user2password"}' \
  https://starwars.jbin.me/api/auth/token/

  • USER add Characters to favorites: [POST] people/favorites/

    Request data arguments :
    List of Character IDs: { [id1, id2, ...] }

Development

curl \
  -X POST \
  -u user2:user2password \
  -H "Content-Type: application/json" \
  -d '[1, 2, 3]' \
  http://127.0.0.1:8002/api/people/favorites/

Live Demo

curl \
  -X POST \
  -H "Authorization: Bearer {acccess token}" \
  -H "Content-Type: application/json" \
  -d '[1, 2, 3]' \
  https://starwars.jbin.me/api/people/favorites/

  • USER views favorite Characters: [GET] people/favorites/

Development

curl \
  -u user2:user2password \
  http://127.0.0.1:8002/api/people/favorites/

Live Demo

curl \
    -H "Authorization: Bearer {acccess token}" \
  https://starwars.jbin.me/api/people/favorites/

Development Mode

Create a python virtual environment and activate it:

python3 -m venv env
source env/bin/activate

Install dependancies from the requirements.txt:

pip install -r requirements.txt

Usage

Populate the DB

You need to run load_people manage.py command after migrate. This needs to run one time to fetch the data from swapi.dev and populate the database.

python manage.py migrate
python manage.py load_people

Add a .env file in root directory with

DEBUG=True

Run development server

python manage.py runserver

About

Django DRF for StarWars characters

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published