Secret Family Recipes Cookbook

back-end by Garrick Suemith

URL

https://tt16-secret-recipes.herokuapp.com

Endpoints

[GET] /api/recipes
[GET] /api/recipes/:id
[POST] /api/recipes
[PUT] /api/recipes/:id
[DELETE] /api/recipes/:id

[POST] /api/auth/register
[POST] /api/auth/login

[GET] /api/users
[GET] /api/users/:id
[GET] /api/users/:id/recipes

[GET] /api/sources [GET] /api/categories [GET] /api/ingredients

[POST] /api/upload/recipe_images/:id

Get all Recipes Summaries

[GET] /api/recipes/
[
  {
    "id": 1,
    "title": "Microwave Ramen",
    "source": "Garrick's College Roommate",
    "contributor": "garrick",
    "categories": ["easy", "asian", "noodles"],
    "description": "A very easy recipe for when you have no time to get your nightly dose of carbs, sodium, and MSG."
  }, 
  {
    "id": 2,
    "title": "Filipino Goulash",
    "image_url": 'something.com',
    "source": "Garrick's Mom",
    "contributor": "garrick",
    "categories": ["dinner", "filipino", "ground pork"],
    "description": "Reminiscent of chili, this hearty dish goes well with steamed rice."
  }
]

Get Full Recipe

[GET] /api/recipes/:id 
// restricted to contributing user
{
  "id": 1,
  "title": "Microwave Ramen",
  "image_url": 'something.com',
  "source": "Garrick's College Roommate",
  "contributor": "garrick",
  "categories": ["easy", "asian", "noodles"],
  "description": "A very easy recipe for when you have no time to get your nightly dose of carbs, sodium, and MSG.",
  "ingredients": [
    {
      "ingredient_id": 1,
      "name": "water",
      "quantity": 2,
      "unit": "cup"
    },
    {
      "ingredient_id": 666,
      "name": "packaged ramen",
      "quantity": 1,
      "unit": "package"
    }
  ],
  "steps": [
    {
      "step_number": 1,
      "instructions": "Put water in microwave safe container and heat on high for 5 minutes or until boiling."
    },
    {
      "step_number": 2,
      "instructions": "Open flavor packet, empty contents into water, and stir."  
    },
    {
      "step_number": 3,
      "instructions": "Place uncooked noodles into broth, cover, and let sit for 5 minutes.  You may heat it further in microwave, stirring occasionally."
    },
    {
      "step_number": 4,
      "instructions": "Allow to cool safely and enjoy."
    }
  ]
}

Submit recipe

[POST] /api/recipes
{
  "title": "Microwave Ramen",
  "image_url": "something.com",
  "source": "Garrick's College Roommate",
  "user_id": 1,
  "categories": ["easy", "asian", "noodles"],
  "description": "A very easy recipe for when you have no time to get your nightly dose of carbs, sodium, and MSG.",
  "ingredients": [
    {
      "name": "water",
      "quantity": 2,
      "unit": "cup"
    },
    {
      "name": "packaged ramen",
      "quantity": 1,
      "unit": "package"
    }
  ],
  "steps": [
    {
      "step_number": 1,
      "instructions": "Put water in microwave safe container and heat on high for 5 minutes or until boiling."
    },
    {
      "step_number": 2,
      "instructions": "Open flavor packet, empty contents into water, and stir."  
    },
    {
      "step_number": 3,
      "instructions": "Place uncooked noodles into broth, cover, and let sit for 5 minutes.  You may heat it further in microwave, stirring occasionally."
    },
    {
      "step_number": 4,
      "instructions": "Allow to cool safely and enjoy."
    }
  ]
}

Update Recipe

[PUT] /api/recipes/:id 
{
  "title": "Microwave Ramen",
  "image_url": "something.com",
  "source": "Garrick's College Roommate",
  "user_id": 1,
  "categories": ["easy", "microwave", "noodles"],
  "description": "A recipe so fast and easy for when you have no time to get your nightly dose of carbs, sodium, and MSG.",
  "ingredients": [
    {
      "name": "water",
      "quantity": 4,
      "unit": "cup"
    },
    {
      "name": "instant ramen noodles",
      "quantity": 2,
      "unit": "package"
    }
  ],
  "steps": [
    {
      "step_number": 1,
      "instructions": "Put water in microwave safe container and heat on high for 5 minutes or until boiling."
    },
    {
      "step_number": 2,
      "instructions": "Open flavor packet, empty contents into water, and stir."  
    },
    {
      "step_number": 3,
      "instructions": "Place uncooked noodles into broth, cover, and let sit for 5 minutes.  You may heat it further in microwave, stirring occasionally."
    },
    {
      "step_number": 4,
      "instructions": "Allow to cool safely and enjoy."
    }
  ]
}
//response is updated object

Delete this recipe

[DELETE] /api/recipes/:id
// response
{
  "Recipe has been deleted"
}

Register

[POST] /api/auth/register
{
  "email": "s@mple.com",
  "username": "sample_user",
  "password": "password"
}

// responds with:
{ 
  "id": 5,
  "email": "s@mple.com",
  "username": "sample_user",
  "password": "password"
}

Log in

[POST] /api/auth/login
{
  "username": "sample_user",
  "password": "password"
}

// responds with:
{
    "message": "Welcome back, sample_user!",
    "token": "eyJhbGc...",
    "user": { 
      "username": "sample_user",
      "email": "s@mple.com",
      "id": 1
    }
}
// tokens expire after 15 minutes

Get list of users

[GET] /api/users
// set Header.Authorization to token
// Accessible only by this logged in user
{
  "username": "garrick",
  "password": "password"
}
// responds with list of users

Get one user

[GET] /api/users/:id
// Accessible by logged in users with matching id
// set Header.Authorization to token
// responds with user info

Get all recipes from one user

[GET] /api/users/:id/recipes

Get a list of recipe resources

[GET] /api/sources
[GET] /api/categories
[GET] /api/ingredients

Upload and image for recipe

[POST] /api/upload/recipe_images/:id