This project is the last step in Udacity Full Stack Developer Nanodegree and the first step in the fully developed web application.
It's a web app for a casting agency where users can add movies, actors, and relate each actor to the movies he acted in, and vice versa.
The backend follows PEP8 style guidelines, and there is no frontend to the app, you can use it by Postman or cURL.
This project uses Python, flask, and Postgresql for its backend and hosted on Haruko.
Follow instructions to install the latest version of python for your platform in the python docs
as a tool to create isolated Python environments.
I recommend working within a virtual environment whenever using Python for projects. This keeps dependencies for each project separate and organaized. Instructions for setting up a virual enviornment for the platform can be found in the python docs
Install dependencies by run
pip3 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 and Flask-SQLAlchemy are libraries to handle the lightweight sqlite database.
-
jose JavaScript Object Signing and Encryption for JWTs. Useful for encoding, decoding, and verifying JWTS.
1- Download the project starter code locally
git clone https://github.com/reemkhd/capstone.git
cd capstone
2- Create an empty repository in your Github account online. To change the remote repository path in your local repository, use the commands below:
git remote -v
git remote remove origin
git remote add origin <https://github.com/<USERNAME>/<REPO_NAME>.git>
git branch -M master
Once you have finished editing your code, you can push the local repository to your Github account using the following commands.
git add . --all
git commit -m "your comment"
git push -u origin master
3- Initialize and activate a virtualenv using:
python -m virtualenv env
source env/bin/activate
Note - In Windows, the env does not have a bin directory. Therefore, you'd use the analogous command shown below:
source env/Scripts/activate
4- Install the dependencies:
pip install -r requirements.txt
5- Running the server:
To run the server, on mac & Linux execute:
export FLASK_APP=app.py
export FLASK_ENV=development
python3 app.py
On Windows:
set FLASK_APP=app.py
set FLASK_ENV=development
python3 app.py
Sourcing setup.sh
sets some environment variables used by the app.
Setting the FLASK_APP
variable to app.py
directs flask to use this file to find the application.
Setting the FLASK_ENV
variable to development
will detect file changes and restart the server automatically.
- Base URL: You can run this API locally at the default http://0.0.0.0:8080
- Authentication: This app has 3 users. Each has his own token which are provided in setup.sh file. Details about each user privlages are provided below.
- GET '/movies'
- GET '/actors'
- POST '/movies'
- POST '/actors'
- PATCH '/movies'
- PATCH '/actors'
- DELETE '/movies'
- DELETE '/actors'
- Fetch all movies info from db
- Request Argument : None
- Returns : JSON response containing all movies with their info, and request status
- Run:
curl -i -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:8080/movies
- The expected result:
{
"movies": [
{
"actors": [
"Tom"
],
"id": 5,
"name": "Blue eyes",
"relase_date": "Tue, 09 Mar 2021 21:45:07 GMT"
}
],
"success": true
}
- Fetch all actors info from db
- Request Argument : None
- Returns : JSON response containing all actors with their info, and request status
- Run:
curl -i -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" http://localhost:8080/actors
- The expected result:
{
"actors": [
{
"movies": [
"My Ajusshi",
"Blue eyes"
],
"id": 1,
"name": "Tom",
"age": 21,
"gendar": "male"
}
],
"success": true
}
- Insert movie info into db
- Request Argument : name, relase date, and actor ID
- Returns: JSON response containing the movie info that inserted, and request status
- Run:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" -d '{"name":"Go", "relase_date":"2021-03-09 21:45:07", "actor_id":5}' http://127.0.0.1:8080/movies
- The expected result:
{
"movie": {
"actors": [
"Ahmad"
],
"id": 5,
"name": "Blue eyes",
"relase_date": "Tue, 09 Mar 2021 21:45:07 GMT"
},
"success": true
}
- Insert actors info into db
- Request Argument : name, age, gendar, and movie ID
- Returns: JSON response containing the actor info that inserted, and request status
- Run:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {INSERT_TOKEN_HERE}" -d '{"name":"Ahmad", "age":43, "gendar":"male", "movies"=2}' http://127.0.0.1:8080/actors
- The expected result:
{
"actor": {
"age": 12,
"gendar": "male",
"id": 3,
"movies": [
"Blue eyes"
],
"name": "Ali"
},
"success": true
}
- Update movies info into db
- Request Argument : Movie ID, name, and relase date
- Returns: JSON response containing the movie info that updated, and request status
- example:
{
"movie": {
"id": 3,
"name": "blue eyes",
"relase_date": "Tue, 09 Mar 2004 21:45:07 GMT"
},
"success": true
}
- Update actors info into db
- Request Argument : Actor ID, name, and gendar
- Returns: JSON response containing the movie info that updated, and request status
- example:
{
"actor": {
"age": 40,
"gendar": "female",
"id": 3,
"movies": [
"Blue eyes"
],
"name": "lolo"
},
"success": true
}
- delete movie from db
- Request Argument : Movie ID
- Returns: JSON response containing request status
- Run:
{
"success": true
}
- delete actor from db
- Request Argument : Actor ID
- Returns: JSON response containing request status
- example:
{
"success": true
}
This app has 3 users. Each has his own token which are provided in setup.sh file.
- Can view actors and movies
- All permissions a Casting Assistant has and…
- Add or delete an actor from the database
- Modify actors or movies
- All permissions a Casting Director has and…
- Add or delete a movie from the database
To run the tests, run
python test_app.py
This app is deployed on heruko under this link.