Create a database of restaurants you have visited or are interested in visiting. Search through your list of restaurants, or just get one by random to mix things up.
This is the capstone project completed for Udacity's Full Stack Web Developer Nanodegree Program.
-
Visit the URL below to get your login link (Resto Rando uses Auth0 as the authentication platform.)
https://resto-rando.herokuapp.com/auth/login -
It should automatically redirect to https://resto-rando.herokuapp.com/auth/result, which will display your access token.
-
Continue below for API endpoint reference.
- Python 3
- Flask: Flask is a lightweight web application framework, used to implement the requests and responses for the API.
- SQLAlchemy: SQLAlchemy is used as the ORM to interface with the PosggreSQL database.
- PostgreSQL 12
- Auth0: Auth0 is used as the authentication and authorization service.
Run the following command in the root folder of the project to install the required python packages.
pip install -r requirements.txt
-
Create a database using the PostgreSQL CLI.
createdb resto_rando
-
Initiate and migrate the database.
flask db upgrade
-
The necessary credentials to run the project are provided in the setup.sh file.
source setup.sh
To run the application on a local development environment, the additional environment variables are necessary.
export FLASK_APP=flaskr export FLASK_ENV=development
-
Run the following command to start the local development server
flask run
-
Create an app in Heroku Cloud. This requires a Heroku account and the Heroku CLI to be installed on your machine.
heroku create resto-rando --buildpack heroku/python
-
Add PostgreSQL addon for the database
heroku addons:create heroku-postgresql:hobby-dev --app resto-rando
-
Specify the required environment variables through the Heroku Dashboard settings.
API_AUDIENCE
AUTH0_DOMAIN
CLIENT_ID
FLASK_APP
REDIRECT_URI
-
Push the application files to Heroku. It will be built on Heroku automatically.
git push heroku main
get:my_resto
: Get data on restaurants added by you.post:resto
: Add restaurant.patch:my_resto
: Edit data for restaurants added by you.delete:my_resto
: Delete restaurants added by you.
All scopes available to user roles +
get:any_resto
: Get data on any restaurant, regardless of user.patch:any_resto
: Edit data for any restaurant, regardless of user.delete:any_resto
: Delete any restaurant, regardless of user.
Erros are returned in the following format:
{
"succcess": false,
"error": 404,
"message": "The server cannot find the requested resource."
}
Some common errors:
401
: Unauthorized403
: Forbidden404
: Not found405
: Method not allowed422
: Request unprocessable
Get the login url.
None.
curl -X GET https://resto-rando.herokuapp.com/auth/login
{
"url": "https://dev-2m33ryh3.us.auth0.com/authorize?audience=resto&response_type=token&client_id=yIpSovVjw5kDcpACpbPDQ9Fekb8khROU&redirect_uri=https://resto-rando.herokuapp.com/auth/results"
}
Get the logout url.
None.
curl -X GET https://resto-rando.herokuapp.com/auth/logout
{
"url": "https://dev-2m33ryh3.us.auth0.com/logout"
}
Get your access token. This endpoint is only available using a browser. Visit the URL here.
None.
Get the list of categories.
None.
curl -X GET https://resto-rando.herokuapp.com/api/categories
{
"success": true,
"categories": {
"0": "African",
"1": "Alcohol",
}
}
The the list of restaurants added by user.
get:my_resto
get:any_resto
: Needed to see restaurants added by other users.
category
(string): Specify single category to filter by.visited
(boolean): Specifytrue
orfalse
to only show from restaurants you have / have not visited.user
(int): Show restaurants added by specified user. If unspecified returns restaurant list based on user role- Admin: All restaurants, regardless of user.
- User: Only restaurants added by logged-in user.
page
(int): Results are paginated (10 restaurants per page). Set value to display specified page, or defaults to first page if unspecified.q
(string): Keyword to search for. Case insensitive.
curl -X GET "https://resto-rando.herokuapp.com/api/restaurants?category=African&page=1" \
--header "Authorization: Bearer $ACCESS_TOKEN"
{
"success": true,
"category": "African",
"visited": null,
"count": 5,
"page": 1,
"restaurants" [
{
"name": "Best Restaurant",
"address": "123 Main Street, New York, NY",
"categories": ["African", "Vegan"],
"visited": true
},
]
}
Add a new restaurant to the database.
post:resto
name
(string, required): Name of the restaurantaddress
(string, required): Restaurant locationcategory
(list, required): Caterogies that match the restaurantvisited
(boolean): Whether this restaurant has been visiteddate_visited
(string): Date visited.YYYY-MM-DD
: Set date visited, uses ISO 8601 style formatting. Automatically setsvisited
totrue
.today
: Set date visited to today. Automatically setsvisited
totrue
.null
: Clears date visited.visited
value kept as is.
curl -X POST https://resto-rando.herokuapp.com/api/restaurants \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"name":"Foo Foods","address":"123 Pacific Drive, Los Angeles, CA","categories":["Asian", "Fast Food"],"visited":false}'
{
"success": true,
"category": null,
"count": 5,
"page": 1,
"restaurants" [
{
"name": "Best Restaurant",
"address": "123 Main Street, New York, NY",
"categories": ["African", "Vegan"],
"visited": true
},
{
"name": "Foo Foods",
"address": "123 Pacific Drive, Los Angeles, CA",
"categories": ["Asian", "Fast Food"],
"visited": false
},
]
}
Edit a restaurant in the database.
patch:my_resto
patch:any_resto
: Needed to edit data on restaurants added by other users.
name
(string): Name of the restaurantaddress
(string): Restaurant locationcategory
(list): Caterogies that match the restaurantvisited
(boolean): Whether this restaurant has been visiteddate_visited
(string): Date visited.YYYY-MM-DD
: Set date visited, uses ISO 8601 style formatting. Automatically setsvisited
totrue
.today
: Set date visited to today. Automatically setsvisited
totrue
.null
: Clears date visited.visited
value kept as is.
curl -X PATCH https://resto-rando.herokuapp.com/api/restaurants/2 \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{"visited": true, "date_visited": "2020-03-14"}'
{
"success": true,
"category": null,
"count": 5,
"page": 1,
"restaurants" [
{
"name": "Best Restaurant",
"address": "123 Main Street, New York, NY",
"categories": ["African", "Vegan"],
"visited": true
},
{
"name": "Foo Foods",
"address": "123 Pacific Drive, Los Angeles, CA",
"categories": ["Asian", "Fast Food"],
"visited": true
},
]
}
Delete a restaurant in the database.
delete:my_resto
delete:any_resto
: Needed to edit data on restaurants added by other users.
curl -X DELETE https://resto-rando.herokuapp.com/api/restaurants/0 \
--header "Authorization: Bearer $ACCESS_TOKEN"
{
"success": true,
"category": null,
"count": 5,
"page": 1,
"restaurants" [
{
"name": "Best Restaurant",
"address": "123 Main Street, New York, NY",
"categories": ["African", "Vegan"],
"visited": true
},
]
}
Get a random restaurant from the database. Results can be restricted by category and visited status.
get:my_resto
category
(string): Specify single category. Result must include this category.visited
(boolean): Specifytrue
orfalse
to only pull from restaurants you have / have not visited.
curl -X GET "https://resto-rando.herokuapp.com/api/restaurants?category=Asian&new" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
{
"success": true,
"category": "Asian",
"visited": true,
"restaurants" [
{
"name": "Foo Foods",
"address": "123 Pacific Drive, Los Angeles, CA",
"categories": ["Asian", "Fast Food"],
"visited": true
}
]
}