HTTPエンドポイントを作成する。
- 以下のエンドポイントを実装する。
POST /recipes-> レシピを作成GET /recipes-> 全レシピ一覧を返すGET /recipes/{id}-> 指定レシピ一つを返すPATCH /recipes/{id}-> 指定レシピを更新DELETE /recipes/{id}-> 指定レシピの削除
- レスポンスは全てJSON形式で返す。
- 上記エンドポイントに対するHTTPレスポンスステータスコードは、すべて
200とする。 - 上記以外のエンドポイントに対するHTTPレスポンスステータスコードは、すべて
404とする。
recipeを新規作成する。- 期待する
request形式:POST /recipestitle,making_time,servers,ingredients,cost- 上記パラメータはすべて必須。
- 期待する
response形式:
成功response
{
"message": "Recipe successfully created!",
"recipe": [
{
"id": 3,
"title": "トマトスープ",
"making_time": "15分",
"serves": "5人",
"ingredients": "玉ねぎ,トマト,スパイス、水",
"cost": "450",
"created_at": "2016-01-12 14:10:12",
"updated_at": "2016-01-12 14:10:12"
}
]
}失敗response
{
"message": "Recipe creation failed",
"required": "title, making_time, serves, ingredients, cost"
}- データベースのすべてのレシピを返す。
- 期待する
request形式:GET /recipes - 期待する
response形式:
{
"recipes": [
{
"id": 1,
"title": "チキンカレー",
"making_time": "45分",
"servers": "4人",
"ingredients": "玉ねぎ,肉,スパイス",
"cost": "1000"
},
{
"id": 2,
"title": "オムライス",
"making_time": "30分",
"servers": "2人",
"ingredients": "玉ねぎ,卵,スパイス,醤油",
"cost": "1000"
},
{
"id": 3,
"title": "トマトスープ",
"making_time": "15分",
"servers": "5人",
"ingredients": "玉ねぎ,トマト,スパイス,水",
"cost": "450"
}
]
}- 指定
idのレシピのみを返します。 - 期待する
request形式:GET /recipes/1 - 期待する
response形式:
{
"message": "Recipe detrails by id"
"recipes": [
{
"id": 1,
"title": "チキンカレー",
"making_time": "45分",
"servers": "4人",
"ingredients": "玉ねぎ,肉,スパイス",
"cost": "1000"
}
]
}- 指定
idのレシピを更新し、更新したレシピを返します。 - 期待する
request形式:PATCH /recipes/{id}Bodyフィールド:title,making_time,servers,ingredients,cost
- 期待する
response形式:
{
"message": "Recipe successfully updated!",
"recipe": [
{
"title": "トマトスープレシピ",
"making_time": "15分",
"serves": "5人",
"ingredients": "玉ねぎ,トマト,スパイス、水",
"cost": "450"
}
]
}- 指定
idのレシピを削除します。 - 期待する
request形式:DELETE /recipes/1 - 期待する
response形式:
成功:
{ "message": "Recipe successfully removed!" }失敗(指定idのレシピが存在しない場合):
{ "message": "No Recipe found" }