The Casting Agency models a company that is responsible for creating movies and managing and assigning actors to those movies. You are an Executive Producer within the company and are creating a system to simplify and streamline your process.
This is the capstone project of Udacity fullstack nanodegree program, which demonstrate the skillset of using Flask, SQLAlchemy, Auth0, gunicorn and heroku to develop and deploy a RESTful API.
Follow instructions to install the latest version of python for your platform in the python docs
We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organaized. Instructions for setting up a virual enviornment for your platform can be found in the python docs
Once you have your virtual environment setup and running, install dependencies by naviging to the /backend
directory and running:
pip install -r requirements.txt
This will install all of the required packages we selected within the requirements.txt
file.
-
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 handle the lightweight sqlite database. You'll primarily work in app.py and can reference models.py.
-
Flask-CORS is the extension we'll use to handle cross origin requests from our frontend server.
With Postgres running, restore a database using the trivia.psql file provided. From the backend folder in terminal run:
psql casting_agency<casting_agency.psql
From within the directory first ensure you are working using your created virtual environment.
To run the server, execute:
. ./setup.sh
flask run
Flask run tests the token headers set for the enviroment. If they have expired, you need to login using the crededntials below and replace them in setup.sh and run setup.sh again
setup.sh has all the environment variables needed for the project. The app may fail if they are not set properly. If that happens just copy paste lines from setup.sh on you CLI.
https://fsnd-casting-agency-udacity.herokuapp.com/
To test live APIs the only way right now to do this is curl requests. Add Auth token headers from logins below to test.
OATH login url. There are three logins atm, JWTs for these appear in the url after successfull login. Those tokens are needed to test the different APIs.
casting Assistant token [email protected] Qwerty1234
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlJWRXNSUnYwWUZRUDdtU3g5VGJ0TSJ9.eyJpc3MiOiJodHRwczovL2Rldi1mYzM0eTlscS51cy5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NWYyMjAzYzNjMTNiMTMwMjI4ZjgxM2FhIiwiYXVkIjoiQ2FzdGluZ0FnZW5jeUFQSSIsImlhdCI6MTU5NjE0MTQ2NSwiZXhwIjoxNTk2M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f9YZegljhEiyZwPtsdlW92KNLNYKkLEPbTPXBwEQl_UmsD769fKc_egvA
To run the tests, run
dropdb casting_agency_test
createdb casting_agency_test
psql casting_agency_test<casting_agency_test.psql
python test_flaskr.py
The tests print data returned from the APIs along with API logs.
The rests also use the Auth token set in env variables and will give an error if the tokens are expired.
Errors are returned as JSON objects in the following format:
{
"success": False,
"error": 400,
"message": "bad request"
}
GET '/actors' POST '/actors' PATCH '/actors/<actor_id>' DELETE '/actors/<actor_id>' GET '/movies' GET '/actors' POST '/actors' PATCH '/actors/<actor_id>' DELETE '/actors/<actor_id>'
GET '/movies' Fetches an array of movies Required URL Arguments: None Required Data Arguments: None Returns: Returns Json data about movies Success Response:
{
"movies":[
{
"genre":"SuperHero",
"id":9,
"release_date":"2019-01-02",
"title":"Avengers"
},
{
"genre":"SuperHero",
"id":10,
"release_date":"2019-01-02",
"title":"Avengers"
}
],
"success":True
}
GET '/actors' Fetches an array of actors Required Data Arguments: None Returns: Json data about actors Success Response:
{
"actors":[
{
"age":22,
"gender":"male",
"id":10,
"name":"rish"
}
],
"success":True
}
DELETE '/movies/int:movie_id' Deletes the movie_id of movie Required URL Arguments: movie_id: movie_id_integer Required Data Arguments: None Returns: deleted movie's ID Success Response:
{'deleted': 8, 'success': True}
DELETE '/actors/int:actor_id' Deletes the actor_id of actor Required URL Arguments: actor_id: actor_id_integer Required Data Arguments: None Returns:the deleted actor's ID Success Response:
{'deleted': 9, 'success': True}
POST '/movies' Post a new movie in a database. Required URL Arguments: None Required Data Arguments: Json data Success Response:
{'movie_id': 11, 'success': True}
POST '/actors' Post a new actor in a database.
Required URL Arguments: None
Required Data Arguments: Json data
Success Response:
{'actor_id': 11, 'success': True}
PATCH '/movies/int:movie_id' Updates the movie_id of movie Required URL Arguments: movie_id: movie_id_integer Required Data Arguments: None Returns: Json data about the updated movie Success Response:
{
"movie":{
"genre":"SuperHero",
"id":9,
"release_date":"2019-01-02",
"title":"Avengers 2"
},
"success":True
}
PATCH '/actors/int:actor_id' Updates the actor_id of actor Required URL Arguments: actor_id: actor_id_integer Required Data Arguments: None Returns: Json data about the modified actor's ID Success Response:
{
"actor":{
"age":22,
"gender":"male",
"id":10,
"name":"gopi"
},
"success":True
}
Rishabh Gajra and The udacity team that made the starter code and Project tasks.