This document provides details about the GraphQL API for the Recipe Book application. The API is hosted at https://recipebookapi.vercel.app/. The Client-app is hosted at https://recipes-book-graphql.vercel.app/.
- Base URL: https://recipebookapi.vercel.app/
- Endpoint:
/
- Request Type: POST
- Content-Type:
application/json
The API supports the following functionality:
- User authentication (registration and login)
- Fetching user details
- CRUD operations for recipes
- Fetching ingredients and categories
POST https://recipebookapi.vercel.app/
Request Body:
{
"query": "mutation registerUser($username: String!, $email: String!, $password: String!) { registerUser(username: $username, email: $email, password: $password) { token user { id username email } } }",
"variables": {
"username": "",
"email": "",
"password": ""
}
}
Response:
{
"data": {
"registerUser": {
"user": {
"id": "",
"username": "",
"email": ""
}
}
}
}
Retrieve details about the authenticated user.
- Query:
query { getUserInformation { id username email } }
- Headers:
Authorization:
Bearer <JWT_TOKEN>
Retrieve all recipes, including their ingredients and related details.
- Query:
query { getRecipes { id title description difficulty time ingredients { id name } category { id name } createdBy { id username } } }
Retrieve a specific recipe by its ID.
- Query:
query getRecipeById($id: ID!) { getRecipeById(id: $id) { id title description difficulty time ingredients { id name } category { id name } createdBy { id username } } }
- Variables:
{ "id": "RECIPE_ID" }
Retrieve all ingredients and their associated recipes.
- Query:
query { getIngredients { id name recipes { id title } } }
Retrieve a specific ingredient by its ID.
- Query:
query getIngredientById($id: ID!) { getIngredientById(id: $id) { id name } }
- Variables:
{ "id": "INGREDIENT_ID" }
Register a new user.
- Mutation:
mutation registerUser($username: String!, $email: String!, $password: String!) { registerUser(username: $username, email: $email, password: $password) { token user { id username email } } }
- Variables:
{ "username": "", "email": "@example.com", "password": "" }
Authenticate a user and retrieve a token.
- Mutation:
mutation loginUser($email: String!, $password: String!) { loginUser(email: $email, password: $password) { token user { id username email } } }
- Variables:
{ "email": "", "password": "" }
Add a new recipe.
- Mutation:
mutation createRecipe( $title: String!, $description: String!, $difficulty: String!, $time: Int!, $ingredients: [String!]!, $category: String!, $createdByUserId: ID! ) { createRecipe( title: $title, description: $description, difficulty: $difficulty, time: $time, ingredients: $ingredients, category: $category, createdByUserId: $createdByUserId ) { id title description difficulty time } }
- Variables:
{ "title": "Pasta Carbonara", "description": "Classic Italian dish.", "difficulty": "Medium", "time": 30, "ingredients": ["Pasta", "Eggs", "Cheese", "Bacon"], "category": "Italian", "createdByUserId": "USER_ID" }
Most queries and mutations require authentication. Use the Authorization
header to provide your token:
Authorization: Bearer <JWT_TOKEN>