Giter Club home page Giter Club logo

render-cloud-example's Introduction

Capstone - Agency API

Capstone project for Udacity Full Stack Developer Nanodegree

The following project models a casting agency that is responsible for creating movies and managing and assigning actors to those movies. It hosts a number of different endpoints that allow specific roles within the agency to perform a different actions such as creating,modifying and deleting movie and actor records.

Project Motivation

The motivation behind this project was to create an application that challenges me and puts into practice a number of new skills I have learnt from the Udacity Full Stack Developer Nanodegree course.

Prerequisite

If you would like to run this project locally please follow the steps below.

1. Install Postgres

The prerequisite to running the app locally is to have a PostgreSQL database available in your local, and the Postgres server must be up and running. Verify the Portgres installation, and start the Postgres server using:

brew install postgresql
postgres --version
pg_ctl -D /usr/local/var/postgres start
pg_ctl -D /usr/local/var/postgres stop

2. Verify the database

Open the psql prompt to view the roles, and databases:

# Open psql prompt
psql [username]
# View the available roles
\du
# View databases
\list

A PostgreSQL database should be available in your Local, and the Postgres server must be up and running.

Running the App Locally

1. Clone Repo

git clone https://github.com/carriescott/render-cloud-example.git

2. Create a virtual environment

Create a virtual environment that will help you keep the Python packages isolated from the ones already installed on your local machine.

cd render-cloud-example
# OPTIONAL - Create a Virtual environment
python3 -m venv myvenv
source myvenv/bin/activate

3. Install PIP Dependencies

Once your virtual environment is set up and running, install the required dependencies by running:

pip install -r requirements.txt

Key Pip Dependencies

  • Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

  • SQLAlchemy is the Python SQL toolkit and ORM we'll use to handle the lightweight SQL database. You'll primarily work in app.pyand can reference models.py.

  • Flask-CORS is the extension we'll use to handle cross-origin requests from our frontend server.

4. Set up the environment variables

Change the DATABASE_URL, to reflect your environment.

# You should have setup.sh and requirements.txt available
chmod +x setup.sh
source setup.sh
# The setup.sh will run the following:
# export DATABASE_URL="postgresql://postgres@localhost:5432/postgres"
# export EXCITED="true"
# Change the DATABASE_URL, as applicable to you.
echo $DATABASE_URL
# postgresql://postgres@localhost:5432/postgres
echo $EXCITED
# true

5. Run the app

python3 app.py

API Reference

Authentication

Successful authentication is required to perform various actions. This API uses Auth0 to define a set of roles and permissions required for each endpoint as outlined below:

  • Casting Assistant
  • Casting Director
    • All permissions a Casting Assistant has and…
    • Add or delete an actor from the database
    • Modify actors or movies
    • Login
  • Executive Producer
    • All permissions a Casting Director has and…
    • Add or delete a movie from the database
    • Login

If you would like to test any of the endpoints outlined in the following section locally you will need to use one of the above logins and grab the access token from the URL. You can then use this token in the authorisation header for your request by passing it in as a bearer token

Login URL: https://carrie-capstone-agency.uk.auth0.com/authorize?audience=https://capstone-agency/&response_type=token&client_id=KvDDalEN7XIjgBD8zLBY8hIcSUU4jPhL&redirect_uri=https://render-cloud-example-0t2l.onrender.com/hello

Endpoints and Expected Behaviour

To test the application in production you will need to use Postman or an equivalent, passing in the access token as described above using the following base url:

Base URL: https://render-cloud-example-0t2l.onrender.com

GET '/actors'

  • Fetches a list of all registered actors
  • Requires get:actors permission
  • Request Arguments: None
  • Returns: An array of objects
{
  "actors": [
    {
      "id": 1,
      "name": "George Clooney",
      "age": 62,
      "gender": "Male"
    },
    {
      "id": 2,
      "name": "Meryl Streep",
      "age": 74,
      "gender": "Female"
    }
  ],
  "success": true
  }

GET '/movies'

  • Fetches a list of all registered movies
  • Requires get:movies permission
  • Request Arguments: None
  • Returns: An array of objects
{
  "movies": [
    {
      "id": 1,
      "title": "Mary Poppins",
      "release_date": 1964
    },
    {
      "id": 2,
      "title": "Cinderella",
      "release_date": 1950
    }
  ],
  "success": true
  }

DELETE '/actors/${id}'

  • Deletes a specified actor using the id of the actor
  • Requires delete:actor permission
  • Request Arguments: id - integer
  • Returns: Does not need to return anything besides the appropriate HTTP status code and the id of the actor.
{
  "success": true,
  "deleted": 1
  }

DELETE '/movies/${id}'

  • Deletes a specified movie using the id of the movie
  • Requires delete:movie permission
  • Request Arguments: id - integer
  • Returns: Does not need to return anything besides the appropriate HTTP status code and the id of the movie.
{
  "success": true,
  "deleted": 1
  }

POST '/actors/create'

  • Creates an actor
  • Requires create:actor permission
  • Request Body:
{
  "id": 2, 
  "name": "Meryl Streep", 
  "age": 74, 
  "gender": "Female"
}
  • Returns: The newly created record and the appropriate HTTP status code.
{
  "success": true,
  "actor": {
      "id": 2,
      "name": "Meryl Streep",
      "age": 74,
      "gender": "Female"
  }
}

POST '/movies/create'

  • Creates a movie
  • Requires create:movie permission
  • Request Body:
{
  "name": "Cinderella",
  "age": 1950
}
  • Returns: The newly created record and the appropriate HTTP status code.
{
  "success": true,
  "movie": {
    "id": 2,
    "title": "Cinderella",
    "release_date": 1950
  }
}

PATCH '/actors/${id}/edit'

  • Edits a specified actor using the id of the actor
  • Requires edit:actor permission
  • Request Arguments: id - integer
  • Request Body: One of the following fields must be provided
{
  "name": "Meryl Streep",
  "age": 74,
  "gender": "Female"
}
  • Returns: The newly created record and the appropriate HTTP status code.
{
  "success": true,
  "actor": {
    "id": 2,
    "name": "Meryl Streep",
    "age": 74,
    "gender": "Female"
  }
}

PATCH '/movies/${id}/edit'

  • Edits a specified movie using the id of the movie
  • Requires edit:movie permission
  • Request Arguments: id - integer
  • Request Body: One of the following fields must be provided
{
  "title": "Mary Poppins",
  "release_date": 1964
}
  • Returns: The newly created record and the appropriate HTTP status code.
{
  "success": true,
  "actor": {
    "id": 1,
    "title": "Mary Poppins",
    "release_date": 1964
  }
}

render-cloud-example's People

Contributors

carriescott avatar ronny-udacity 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.