Skip to content

A ruby/sinatra JSON api to access stored recipes

Notifications You must be signed in to change notification settings

jz333/recipe_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

recipe_api

A ruby/sinatra JSON api to access stored recipes

GET route that returns all recipe names.

A GET request to *http://localhost:3000/recipes* returns:
*Response body (JSON):*
{
	"recipeNames":
		[
			"scrambledEggs",
			"garlicPasta",
			"chai"
		]
}
*Status: 200*

GET route that takes a recipe name as a string param. Return the ingredients and the number of steps in the recipe as JSON

A GET request to http://localhost:3000/recipes/details/garlicPasta returns:
*If recipe exists:*
*Response body (JSON):*
{
	"details":
		{
			"ingredients": [
				"500mL water",
				"100g spaghetti",
				"25mL olive oil",
				"4 cloves garlic",
				"Salt"
			],
			"numSteps":5
		}
}
*Status: 200
---
If recipe does NOT exist: 
Response body (JSON)*: {}
*Status*: 200

POST route that can add additional recipes in the existing format to the backend with support for the above routes.

A POST request to **http://localhost:3000/recipes** with body 
{
	"name": "butteredBagel", 
		"ingredients": [
			"1 bagel", 
			"butter"
		], 
	"instructions": [
		"cut the bagel", 
		"spread butter on bagel"
	] 
} 
returns:
*Response body: None*
*Status:* 201

Error Response:

If the recipe already exists:

*Response body (JSON):*
{
	"error": "Recipe already exists"
}
*Status: 400*

PUT route that can update existing recipes.

A PUT request to **http://localhost:3000/recipes** with body 
{
	"name": "butteredBagel", 
		"ingredients": [
			"1 bagel", 
			"2 tbsp butter"
		], 
	"instructions": [
		"cut the bagel", 
		"spread butter on bagel"
	] 
} returns:
*Response body: None*
*Status:* 204

Error Response:

If the recipe doesn't exist:

*Response body (JSON):*
{
	"error": "Recipe does not exist"
}
*Status: 404*

About

A ruby/sinatra JSON api to access stored recipes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages