Recipebook API Documentation

๐Ÿณ Recipebook API

This API allows users to register, login, and manage recipes using REST or GraphQL.


๐Ÿš€ Base URL

https://recipebook.fly.dev

๐Ÿ” Authentication

The API uses JWT tokens. Include the token in the Authorization header:

Authorization: Bearer <token>

Register

POST /register
curl -X POST https://recipebook.fly.dev/register \
-H "Content-Type: application/json" \
-d '{
  "user": {
    "email": "user@example.com",
    "password": "password",
    "password_confirmation": "password"
  }
}'

Response

{
  "token": "your_jwt_token"
}

Login

POST /login
curl -X POST https://recipebook.fly.dev/login \
-H "Content-Type: application/json" \
-d '{
  "email": "user@example.com",
  "password": "password"
}'

Response

{
  "token": "your_jwt_token"
}

๐Ÿ“˜ REST API

Get All Recipes

GET /recipes
curl https://recipebook.fly.dev/recipes

Response

[
  {
    "id": 1,
    "name": "Tacos",
    "ingredients": "Tortillas, Beef, Lettuce",
    "instructions": "Cook beef and assemble tacos"
  }
]

Get One Recipe

GET /recipes/1
curl https://recipebook.fly.dev/recipes/1

Create Recipe

POST /recipes
curl -X POST https://recipebook.fly.dev/recipes \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
  "recipe": {
    "name": "Pizza",
    "ingredients": "Flour, Cheese, Tomato",
    "instructions": "Bake at 220ยฐC"
  }
}'

Update Recipe

PATCH /recipes/1
curl -X PATCH https://recipebook.fly.dev/recipes/1 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{
  "recipe": {
    "name": "Updated Pizza"
  }
}'

Delete Recipe

DELETE /recipes/1
curl -X DELETE https://recipebook.fly.dev/recipes/1 \
-H "Authorization: Bearer <token>"

Response

{
  "message": "Recipe deleted"
}

๐Ÿ”ต GraphQL API

POST /graphql
https://recipebook.fly.dev/graphql

Query All Recipes

{
  "query": "query { recipes { id name ingredients } }"
}

Query Single Recipe

{
  "query": "query { recipe(id: 1) { id name instructions } }"
}

Create Recipe

{
  "query": "mutation {
    createRecipe(input: {
      name: \"Burger\",
      ingredients: \"Beef, Bun, Cheese\",
      instructions: \"Cook and assemble\"
    }) {
      recipe {
        id
        name
      }
      errors
    }
  }"
}

Update Recipe

{
  "query": "mutation {
    updateRecipe(input: {
      id: 1,
      name: \"Updated Burger\"
    }) {
      recipe {
        id
        name
      }
      errors
    }
  }"
}

Delete Recipe

{
  "query": "mutation {
    deleteRecipe(input: {
      id: 1
    }) {
      success
      errors
    }
  }"
}

๐Ÿงช Example Workflow

  1. Register user
  2. Login and copy token
  3. Create recipe
  4. List recipes
  5. Update recipe
  6. Delete recipe

โœ… Status Codes