Heroku Link: https://my-udacity-capstone-project.herokuapp.com
While running locally: http://localhost:5000
Follow instructions to install the latest version of python for your platform in the python docs.
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 running:
pip install -r requirements.txtThis will install all of the required packages.
-
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.
Before running the application locally, make the following changes in the app.py file in root directory:
- uncomment the line
db_drop_and_create_all()on the initial run to setup the required tables in the database.
To run the server, execute:
export DATABASE_URL=<database-connection-url>
export FLASK_APP=app.py
flask run --reloadSetting the FLASK_APP variable to app.py directs flask to use the app.py file to find the application.
Using the --reload flag will detect file changes and restart the server automatically.
Base URL: This application can be run locally. The hosted version is at https://my-udacity-capstone-project.herokuapp.com/.
Authentication: This application requires authentication to perform various actions. All the endpoints require
various permissions, except the root endpoint, that are passed via the Bearer token.
The application has three different types of roles:
- Assistant
- can only view the list of actors and movies.
- has
view:actors, view:moviespermissions.
- Director
- can perform all the actions that
Assistantcan. - can only create an actor and also update respective information.
- has
add:actors, delete:actors, edit:actors, edit:movies, view:actors, view:moviespermissions.
- can perform all the actions that
- Producer
- can perform all the actions that
Directorcan. - can also add an actor or a movie, edit and delete any actor or movie.
- has
add:actors, add:movies, delete:actors, delete:movies, edit:actors, edit:movies, get:movies, view:actors, view:moviespermissions.
- can perform all the actions that
Errors are returned as JSON objects in the following format:
{
"success": false,
"error": 404,
"message": "resource not found"
}
The API will return the following errors based on how the request fails:
- 401: Unauthorized
- 404: Not Found
- 422: Unprocessable Entity
- 500: Internal Server Error
-
General
- root endpoint
- can also work to check if the api is up and running
- is a public endpoint, requires no authentication
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com
Sample Response
{
"Status": "yay its work well"
}
-
General
- gets the list of all the actors
- requires
view:actorspermission
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/actors
Sample Response
{
"actors": [
{
"age": 30,
"id": 1,
"name": "Hey its my name!"
}
]
}
-
General
- creates a new actor.
- requires
add:actorspermission.
-
Request Body
- name: string, required.
- age: Integer, required.
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/actors/create- Request Body
{ "name": "Hey its my name!", "age": 30 }
Sample Response
{
"success": true
}
-
General
- updates the info for an actor
- requires
edit:actorspermission
-
Request Body (at least one of the following fields required)
- name: string, optional.
- age: Integer, required.
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/actors/1- Request Body
{ "age": 32 }
Sample Response
{
"success": true,
"id": 1
}
-
General
- deletes an actor
- requires
delete:actorspermission
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/actors/1
Sample Response
{
"success": true,
"id": 1
}
-
General
- gets the list of all the movies
- requires
view:moviespermission
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/movies
Sample Response
{
"movies": [
{
"id": 1,
"releaseDate": "08/02/2019",
"title": "movie title example"
},
{
"id": 2,
"releaseDate": "10/02/2019",
"title": "another movie title example"
}
]
}
-
General
- creates a new movie.
- requires
add:moviespermission.
-
Request Body
- title: string, required.
- releaseDate: integer, required.
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/movies/create- Request Body
{ "title": "Spider Man", "releaseDate": 2019, }
Sample Response
{
"success": true
}
-
General
- updates the info for a movie
- requires
edit:moviespermission
-
Request Body (at least one of the following fields required)
- title: string, optional
- releaseDate: integer, optional
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/movies/3- Request Body
{ "releaseDate": 2017 }
Sample Response
{
"success": true,
"id": 3
}
-
General
- deletes a movie
- requires
delete:moviespermission
-
Sample Request
https://my-udacity-capstone-project.herokuapp.com/movies/3
Sample Response
{
"success": true,
"id": 3
}
For testing the backend, run the following commands (in the exact order):
dropdb capstone_test
createdb capstone_test
psql capstone_test < capstone.pgsql
python test.py
For testing the backend, run the following commands (in the exact order):
dropdb -U <DATABASE USER> capstone_test
createdb -U <DATABASE USER> capstone_test
psql -U <DATABASE USER> capstone_test < capstone.pgsql
py test.py
Alternate way: Create the db capstone_test using PgAdmin and copy the contents of casting.pgsql and paste them
in Query tool in PgAdmin and create the db table with records. Then, run the command for MAC OS python test.py or py test.py for Windows OS.