Capstone is a casting agency that finds and grooms talented aspiring actors, providing a platform for them develop the skills needed to become movie stars. Capstone also houses a large database of actors and movies around the world.
A running API is deployed on Heroku. Explore the API with Postman via the URL https://capstone66.herokuapp.com/.
Kindly see the jwt_tokens.txt file for test tokens.
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.
python3.7 -m venv
source venv/bin/activate
With Postgres running, restore a database using the command below. The command will create tables and insert seed data.
source ./setup.sh
- IMPORTANT: create a
.env
file in theroot directory
that contains your database path. Use theenv.example
file for reference.
Once you have your virtual environment setup and running, install dependencies 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.
-
Python-Jose is used to encrypt/decrypt and/or sign content using a variety of JWT algorithms.
From within the root directory
, first ensure you are working from a virtual environment and the setup.sh
file is run.
To run the server, execute:
export FLASK_APP=app.py
export FLASK_ENV=development
flask run
Setting the FLASK_ENV
variable to development
will detect file changes and restart the server automatically.
Setting the FLASK_APP
variable to app.py
directs flask to use the app.py
file where our server lives.
The endpoints of this API are protected with JWT. A valid token is required to interract with endpoints. Kindly check the jwt_tokens.txt file in repo for sample tokens for test. Tokens will expire 24 hours after being generated
# Actors
POST '/actors'
GET '/actors'
GET '/actors/<actor_id>'
PATCH '/actors/<actor_id>'
DELETE '/actors/<actor_id>'
# Movies
POST '/movies'
GET '/movies'
GET '/movies/<movie_id>'
PATCH '/movies/<movie_id>'
DELETE '/movies/<movie_id>'
Adds an actor to the database.
- Permission:
post:actors
- Request params:
None
Request body:
{
"name": "Asajj Ventress",
"age": 27,
"gender": "female"
}
Response:
{
"actor": {
"age": 27,
"gender": "female",
"id": 4,
"name": "Asajj Ventress"
},
"message": "created",
"success": true
}
Fetches all actors from the database with pagination.
- Permission:
get:actors
- Request query params (integer):
page
Response
{
"actors": [
{
"age": 20,
"gender": "male",
"id": 1,
"name": "Anakin Skywalker"
},
{
"age": 23,
"gender": "male",
"id": 2,
"name": "Luke Shaw"
},
{
"age": 26,
"gender": "female",
"id": 3,
"name": "Padme Amidala"
}
],
"success": true,
"total_results": 3
}
Fetches an actor from the database by unique id
.
- Permission:
get:actors
- Request path params (integer):
actor_id
Response
{
"actor": {
"age": 27,
"gender": "female",
"id": 4,
"name": "Asajj Ventress"
},
"success": true
}
Updates an actor in the database by unique id
.
- Permission:
patch:actors
- Request Path Params (integer):
actor_id
Request body:
{
"name": "Asajj Ventress",
"age": 30,
"gender": "female"
}
Response
{
"actor": {
"age": 30,
"gender": "female",
"id": 4,
"name": "Asajj Ventress"
},
"success": true
}
Delete an actor entry in the database by unique id
.
- Permission:
delete:actors
- Request Path Params (integer):
actor_id
- Request body:
None
Response
{
"actor_id": 4,
"message": "deleted",
"success": true
}
Adds an movie to the database.
- Permission:
post:movies
- Request params:
None
Request body:
{
"title": "Star Wars: The Clone Wars",
"release_date": "2015-12-4"
}
Response:
{
"message": "created",
"movie": {
"id": 4,
"release_date": "Tue, 04 Dec 2015 00:00:00 GMT",
"title": "Star Wars: The Clone Wars"
},
"success": true
}
Fetches all movies from the database with pagination.
- Permission:
get:movies
- Request query params (integer):
page
Response
{
"movies": [
{
"id": 1,
"release_date": "Thu, 12 Oct 2017 00:00:00 GMT",
"title": "Star Wars: Episode I"
},
{
"id": 2,
"release_date": "Thu, 12 Oct 2017 00:00:00 GMT",
"title": "Star Wars: Episode II"
},
{
"id": 3,
"release_date": "Thu, 12 Oct 2017 00:00:00 GMT",
"title": "Star Wars: Episode III"
}
],
"success": true,
"total_results": 3
}
Fetches an movie from the database by unique id
.
- Permission:
get:movies
- Request path params (integer):
movie_id
Response
{
"movie": {
"id": 3,
"release_date": "Thu, 12 Oct 2017 00:00:00 GMT",
"title": "Movie1"
},
"success": true
}
Updates an movie in the database by unique id
.
- Permission:
patch:movies
- Request Path Params (integer):
movie_id
Request body:
{
"title": "Movie update",
"release_date": "2019-10-11"
}
Response
{
"movie": {
"id": 3,
"release_date": "Fri, 11 Oct 2019 00:00:00 GMT",
"title": "Movie update"
},
"success": true
}
Delete an movie entry in the database by unique id
.
- Permission:
delete:movies
- Request Path Params (integer):
movie_id
- Request body:
None
Response
{
"movie_id": 4,
"message": "deleted",
"success": true
}
Errors are returned as JSON objects in the following format:
{
"success": False/True,
"error": status_code,
"message": "Error message"
}
The API will return three error types with the following messages when requests fail:
- 400: Bad Request
- 401: Unauthorized
- 403: Not Permitted
- 404: Resource Not Found
- 422: Not Processable
- 500: Internal server error
To run the tests, run
python test_app.py
Ovie Udih