这里我有一个json数据,data.json
{
"recipes": [
{
"name": "scrambledEggs",
"ingredients": [
"1 tsp oil",
"2 eggs",
"salt"
],
"instructions": [
"Beat eggs with salt",
"Heat oil in pan",
"Add eggs to pan when hot",
"Gather eggs into curds, remove when cooked",
"Salt to taste and enjoy"
]
},
{
"name": "garlicPasta",
"ingredients": [
"500mL water",
"100g spaghetti",
"25mL olive oil",
"4 cloves garlic",
"Salt"
],
"instructions": [
"Heat garlic in olive oil",
"Boil water in pot",
"Add pasta to boiling water",
"Remove pasta from water and mix with garlic olive oil",
"Salt to taste and enjoy"
]
},
{
"name": "chai",
"ingredients": [
"400mL water",
"100mL milk",
"5g chai masala",
"2 tea bags or 20 g loose tea leaves"
],
"instructions": [
"Heat water until 80 C",
"Add milk, heat until 80 C",
"Add tea leaves/tea bags, chai masala; mix and steep for 3-4 minutes",
"Remove mixture from heat; strain and enjoy"
]
}
]
}
创建一个SpringBoot的api,要求如下
part 1
A GET request to http://localhost:3000/recipes returns:
Response body (JSON):
{
"recipeNames":
[
"scrambledEggs",
"garlicPasta",
"chai"
]
}
Status: 200
part 2
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
part 3
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
// 已存在
Response body (JSON):
{
"error": "Recipe already exists"
}
Status: 400
part 4
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
//不存在
Response body (JSON):
{
"error": "Recipe does not exist"
}
Status: 404