This is the api for the recipe app I made for my second WDI project. It's a simple API that adds only a single table to the base template provided. There are some custom routes setup and a relation between the recipes and users tables.
Overall ruby on rails did most of the work, I was just the overseer. All the magic was done with really just two migration files. The rest of the magic happens with the client which is linked below.
I would like to add more tables - giving me more functionality. The plan would be a many to many join table between recipes and ingredients as well as a CSV file to popluate the ingredients table. Perhaps there are some third party APIs I can employ in the future as well as this may carry over to my capstone project.
After Capsstone:
I have added a new table and new relations. I need to document this information.
For now be aware there is a new table called pictures that needs to be documented.
It has a restful convention and uses recipe_id as a foreign key to associate to its respective recipe.
This template follows the standard project structure in Rails 4.
curl
command scripts are stored in scripts
with names that
correspond to API actions.
User authentication is built-in.
Developers should run these often!
bin/rake routes
lists the endpoints available in your API.bin/rake test
runs automated tests.bin/rails console
opens a REPL that pre-loads the API.bin/rails db
opens your database client and loads the correct database.bin/rails server
starts the API.scripts/*.sh
run variouscurl
commands to test the API. See below.
Use this as the basis for your own API documentation. Add a new third-level heading for your custom entities, and follow the pattern provided for the built-in user authentication documentation.
Scripts are included in scripts
to test built-in actions. Add your
own scripts to test your custom API. As an alternative, you can write automated
tests in RSpec to test your API.
Verb | URI Pattern | Controller#Action |
---|---|---|
POST | /sign-up |
users#signup |
POST | /sign-in |
users#signin |
PATCH | /change-password/:id |
users#changepw |
DELETE | /sign-out/:id |
users#signout |
Request:
curl http://localhost:4741/sign-up \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASSWORD}"'",
"password_confirmation": "'"${PASSWORD}"'"
}
}'
EMAIL=ava@bob.com PASSWORD=hannah scripts/sign-up.sh
Response:
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "ava@bob.com"
}
}
Request:
curl http://localhost:4741/sign-in \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASSWORD}"'"
}
}'
EMAIL=ava@bob.com PASSWORD=hannah scripts/sign-in.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "ava@bob.com",
"token": "BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f"
}
}
Request:
curl --include --request PATCH "http://localhost:4741/change-password/$ID" \
--header "Authorization: Token token=$TOKEN" \
--header "Content-Type: application/json" \
--data '{
"passwords": {
"old": "'"${OLDPW}"'",
"new": "'"${NEWPW}"'"
}
}'
ID=1 OLDPW=hannah NEWPW=elle TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/change-password.sh
Response:
HTTP/1.1 204 No Content
Request:
curl http://localhost:4741/sign-out/$ID \
--include \
--request DELETE \
--header "Authorization: Token token=$TOKEN"
ID=1 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/sign-out.sh
Response:
HTTP/1.1 204 No Content
Verb | URI Pattern | Controller#Action |
---|---|---|
GET | /users |
users#index |
GET | /users/1 |
users#show |
Request:
curl http://localhost:4741/users \
--include \
--request GET \
--header "Authorization: Token token=$TOKEN"
TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/users.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"users": [
{
"id": 2,
"email": "bob@ava.com"
},
{
"id": 1,
"email": "ava@bob.com"
}
]
}
Request:
curl --include --request GET http://localhost:4741/users/$ID \
--header "Authorization: Token token=$TOKEN"
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 2,
"email": "bob@ava.com"
}
}
Verb | URI Pattern | Controller#Action |
---|---|---|
POST | /recipes |
create |
GET | /recipes |
index |
GET | /recipes/:id |
show |
PATCH | /recipes/:id |
update |
DELETE | /recipes/:id |
destroy |
Request:
curl --include --request POST http://localhost:4741/recipes \
--header "Content-Type: application/json" \
--header "Authorization: Token token=$TOKEN"
--data '{
"recipe": {
"title": "Some recipe",
"ingredient_list": "some ingredients",
"directions": "cook it",
"prep_time": "too long"
}
}'
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
Completed 201 Created
Content-Type: application/json; charset=utf-8
{
"recipe": {
"directions": "Made it",
"id": "50",
"ingredient_list": "Things and stuff",
"prep_time": "quick",
"title": "Next recipe"
}
}
Request:
curl --include --request GET http://localhost:4741/recipes\
--header "Authorization: Token token=$TOKEN"
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
Completed 200 OK
Content-Type: application/json; charset=utf-8
{
"recipes": {
"directions": "Made it",
"id": "50",
"ingredient_list": "Things and stuff",
"prep_time": "quick",
"title": "Next recipe"
},
{
"directions": "Make it make it real good",
"id": "51",
"ingredient_list": "Things and stuff",
"prep_time": "not quick",
"title": "My recipe"
}
}
Request:
curl --include --request GET http://localhost:4741/recipes/$ID\
--header "Authorization: Token token=$TOKEN"\
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
Completed 200 OK
Content-Type: application/json; charset=utf-8
{
"recipes": {
"directions": "Made it",
"id": "50",
"ingredient_list": "Things and stuff",
"prep_time": "quick",
"title": "Next recipe"
}
}
Request:
curl --include --request PATCH http://localhost:4741/recipes/$ID\
--header "Authorization: Token token=$TOKEN"\
--data '{
"recipe": {
"directions": "cook it, cook it real good"
}
}'
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
Completed 200 OK
Content-Type: application/json; charset=utf-8
{
"recipes": {
"directions": "cook it, cook it real good",
"id": "50",
"ingredient_list": "Things and stuff",
"prep_time": "quick",
"title": "Next recipe"
}
}
Request:
curl --include --request PATCH http://localhost:4741/recipes/$ID\
--header "Authorization: Token token=$TOKEN"\
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
Completed 200 OK
Content-Type: application/json; charset=utf-8
header empty
This is not a task developers should run often, but it is sometimes necessary.
locally
bin/rake db:migrate VERSION=0
bin/rake db:migrate db:seed db:examples
heroku
heroku run rake db:migrate VERSION=0
heroku run rake db:migrate db:seed db:examples
Production URL:https://recipe-card-backend.herokuapp.com/
Repo:https://github.com/antleo1995/recipe_card_app_api Ember repo: https://github.com/antleo1995/ember-recipe-app
Back end deployed: https://recipe-card-backend.herokuapp.com/
Production URL:https://antleo1995.github.io/recipe_card_app/ Ember deployed app: https://antleo1995.github.io/ember-recipe-app/ Front end deployed: https://antleo1995.github.io/ember-recipe-app/ Repo:https://github.com/antleo1995/recipe_card_app
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.