Skip to content

kkato/recipe-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

recipe-api

HTTPエンドポイントを作成する。

  • 以下のエンドポイントを実装する。
    • POST /recipes -> レシピを作成
    • GET /recipes -> 全レシピ一覧を返す
    • GET /recipes/{id} -> 指定レシピ一つを返す
    • PATCH /recipes/{id} -> 指定レシピを更新
    • DELETE /recipes/{id} -> 指定レシピの削除
  • レスポンスは全てJSON形式で返す。
  • 上記エンドポイントに対するHTTPレスポンスステータスコードは、すべて200とする。
  • 上記以外のエンドポイントに対するHTTPレスポンスステータスコードは、すべて404とする。

POST /recipesエンドポイント

  • recipeを新規作成する。
  • 期待するrequest形式: POST /recipes
    • title, 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"
}

GET /recipesエンドポイント

  • データベースのすべてのレシピを返す。
  • 期待する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"
        }
    ]
}

GET/recipes/{id}エンドポイント

  • 指定idのレシピのみを返します。
  • 期待するrequest形式: GET /recipes/1
  • 期待するresponse形式:
{
    "message": "Recipe detrails by id"
    "recipes": [
        {
            "id": 1,
            "title": "チキンカレー",
            "making_time": "45分",
            "servers": "4人",
            "ingredients": "玉ねぎ,肉,スパイス",
            "cost": "1000"
        }
    ]
}

PATCH /recipes/{id}エンドポイント

  • 指定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"
        }
    ]
}

DELETE /recipes/{id}エンドポイント

  • 指定idのレシピを削除します。
  • 期待するrequest形式: DELETE /recipes/1
  • 期待するresponse形式:

成功:

{   "message": "Recipe successfully removed!"   }

失敗(指定idのレシピが存在しない場合):

{   "message": "No Recipe found"   }

About

レシピ管理 API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •