API Documentation
Documentation for the Recipe App API
Authenticate
Description: Register a new user
URL: /api/register
Method: POST
Parameters:
name(required) - The user's nameemail(required, unique) - The user's emailpassword(required, min 6 characters) - The user's password
Response (201):
{
"status": "success",
"message": "Registration successful",
"data": {
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
},
"token": "auth_token"
}
}
Error Response (422):
{
"status": "error",
"message": "Validation failed",
"errors": {
"email": ["The email has already been taken."]
}
}
Error Response (500):
{
"status": "error",
"message": "Failed to register user",
}
Description: Log in a user
URL: /api/login
Method: POST
Parameters:
email(required) - The user's emailpassword(required) - The user's password
Response (200):
{
"status": "success",
"message": "Login successful",
"data": {
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
},
"token": "auth_token"
}
}
Error Response (401):
{
"status": "error",
"message": "Invalid credentials"
}
Description: Log out the current user
URL: /api/logout
Method: POST
Headers:
Authorization(required) - Bearer token
Response (200):
{
"status": "success",
"message": "Logged out successfully"
}
Error Response (500):
{
"status": "error",
"message": "Failed to log out",
"error": "error_details"
}
Recipe
Description: Retrieve a paginated list of recipes
URL: /api/recipes
Method: GET
Headers:
Authorization(required) - Bearer token
Response (200):
{
"status": "success",
"message": "Recipes retrieved successfully",
"data": {
"current_page": 1,
"data": [
{
"id": 3,
"user_id": 3,
"title": "judul 5",
"description": "deskripsi 1",
"cooking_method": "cooking 5",
"ingredients": "inggridiens 1",
"photo_url": "https://www.freeapi.tahuaci.com/storage/photos/kFEqdkGkcG8XAf8OiAnps0tuORwLdFAFQlaAGLag.jpg",
"created_at": "2024-10-30T02:52:02.000000Z",
"updated_at": "2024-11-05T04:15:45.000000Z",
"likes_count": 2,
"comments_count": 0,
"user": {
"id": 3,
"name": "Arif",
"email": "hyda.arif2@gmail.com",
"email_verified_at": null,
"created_at": "2024-10-22T08:35:00.000000Z",
"updated_at": "2024-10-22T08:35:00.000000Z"
}
},
...
],
"first_page_url": "http://127.0.0.1:8000/api/recipes?page=1",
"from": 1,
"next_page_url": null,
"path": "http://127.0.0.1:8000/api/recipes",
"per_page": 12,
"prev_page_url": null,
"to": 3
}
}
Description: Create a new recipe
URL: /api/recipes
Method: POST
Headers:
Authorization(required) - Bearer token
Parameters:
title(required) - The title of the recipecooking_method(required) - The method of cookingingredients(required) - The ingredientsdescription(required) - Recipe descriptionphoto(required, image) - Recipe image file
Response (201):
{
"status": "success",
"message": "Recipe created successfully",
"data": { "id": 1, "title": "Recipe Title", ... }
}
Error Response (422):
{
"status": "error",
"message": "Validation failed",
"errors": { "title": ["The title field is required."] }
}
Description: Retrieve a specific recipe by ID
URL: /api/recipes/{id}
Method: GET
Headers:
Authorization(required) - Bearer token
Response (200):
{
"status": "success",
"message": "Recipe retrieved successfully",
"data": { "id": 1, "title": "Recipe Title", ... }
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Update an existing recipe
URL: /api/recipes/{id}
Method: PUT
Headers:
Authorization(required) - Bearer token
Parameters: (All parameters are optional - only include fields you want to update)
title(optional) - The title of the recipecooking_method(optional) - The method of cookingingredients(optional) - The ingredientsdescription(optional) - Recipe description
Note: The photo cannot be modified. Only the recipe owner can update their own recipes.
Response (200):
{
"status": "success",
"message": "Recipe updated successfully",
"data": { "id": 1, "title": "Updated Recipe Title", ... }
}
Error Response (403):
{
"status": "error",
"message": "Unauthorized. You can only update your own recipes"
}
Error Response (422):
{
"status": "error",
"message": "Validation failed",
"errors": {
"title": ["The title field is required."]
}
}
Error Response (500):
{
"status": "error",
"message": "Failed to update recipe",
"error": "error_details"
}
Description: Delete a recipe by ID. Only the recipe owner can delete their own recipes.
URL: /api/recipes/{id}
Method: DELETE
Headers:
Authorization(required) - Bearer token
Response (200):
{
"status": "success",
"message": "Recipe deleted successfully"
}
Error Response (403):
{
"status": "error",
"message": "Unauthorized. You can only delete your own recipes"
}
Error Response (500):
{
"status": "error",
"message": "Failed to delete recipe",
"error": "error_details"
}
Like
Description: Toggle like/unlike a recipe. If already liked, it will unlike. If not liked, it will like.
URL: /api/recipes/{recipe}/like
Method: POST
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe ID
Response (200):
{
"status": "success",
"message": "Recipe liked successfully",
"data": {
"is_liked": true,
"like_count": 5
}
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Unlike a recipe
URL: /api/recipes/{recipe}/unlike
Method: DELETE
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe ID
Response (200):
{
"status": "success",
"message": "Recipe unliked successfully",
"data": {
"is_liked": false,
"like_count": 4
}
}
Error Response (400):
{
"status": "error",
"message": "You have not liked this recipe"
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Get all likes for a recipe
URL: /api/recipes/{recipe}/likes
Method: GET
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe ID
Response (200):
{
"status": "success",
"message": "Likes retrieved successfully",
"data": {
"likes": [
{
"id": 1,
"user_id": 1,
"recipe_id": 1,
"created_at": "2024-10-22T01:24:44.000000Z",
"updated_at": "2024-10-22T01:24:44.000000Z",
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
}
}
],
"like_count": 1,
"is_liked": true
}
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Check if the authenticated user has liked a recipe
URL: /api/recipes/{recipe}/check-like
Method: GET
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe ID
Response (200):
{
"status": "success",
"data": {
"is_liked": true
}
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Comment
Description: Get all comments for a recipe
URL: /api/recipes/{recipe}/comments
Method: GET
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe ID
Response (200):
{
"status": "success",
"message": "Comments retrieved successfully",
"data": {
"comments": [
{
"id": 1,
"user_id": 1,
"recipe_id": 1,
"comment": "Great recipe!",
"created_at": "2024-10-22T01:24:44.000000Z",
"updated_at": "2024-10-22T01:24:44.000000Z",
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
}
}
],
"comment_count": 1
}
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Create a new comment on a recipe
URL: /api/recipes/{recipe}/comments
Method: POST
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe ID
Body Parameters:
comment(required, string, max 1000 characters) - The comment text
Response (201):
{
"status": "success",
"message": "Comment added successfully",
"data": {
"id": 1,
"user_id": 1,
"recipe_id": 1,
"comment": "Great recipe!",
"created_at": "2024-10-22T01:24:44.000000Z",
"updated_at": "2024-10-22T01:24:44.000000Z",
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
}
}
}
Error Response (422):
{
"status": "error",
"message": "Validation failed",
"errors": {
"comment": ["The comment field is required."]
}
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Get a specific comment by ID
URL: /api/recipes/{recipe}/comments/{comment}
Method: GET
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe IDcomment(required) - Comment ID
Response (200):
{
"status": "success",
"message": "Comment retrieved successfully",
"data": {
"id": 1,
"user_id": 1,
"recipe_id": 1,
"comment": "Great recipe!",
"created_at": "2024-10-22T01:24:44.000000Z",
"updated_at": "2024-10-22T01:24:44.000000Z",
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
}
}
}
Error Response (400):
{
"status": "error",
"message": "Comment does not belong to this recipe"
}
Error Response (404):
{
"status": "error",
"message": "Recipe not found"
}
Description: Update a comment. Only the comment owner can update their own comment.
URL: /api/recipes/{recipe}/comments/{comment}
Method: PUT
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe IDcomment(required) - Comment ID
Body Parameters:
comment(required, string, max 1000 characters) - The updated comment text
Response (200):
{
"status": "success",
"message": "Comment updated successfully",
"data": {
"id": 1,
"user_id": 1,
"recipe_id": 1,
"comment": "Updated comment text",
"created_at": "2024-10-22T01:24:44.000000Z",
"updated_at": "2024-10-22T01:25:00.000000Z",
"user": {
"id": 1,
"name": "User Name",
"email": "user@example.com"
}
}
}
Error Response (403):
{
"status": "error",
"message": "Unauthorized. You can only update your own comments"
}
Error Response (422):
{
"status": "error",
"message": "Validation failed",
"errors": {
"comment": ["The comment field is required."]
}
}
Description: Delete a comment. Only the comment owner can delete their own comment.
URL: /api/recipes/{recipe}/comments/{comment}
Method: DELETE
Headers:
Authorization(required) - Bearer token
URL Parameters:
recipe(required) - Recipe IDcomment(required) - Comment ID
Response (200):
{
"status": "success",
"message": "Comment deleted successfully"
}
Error Response (403):
{
"status": "error",
"message": "Unauthorized. You can only delete your own comments"
}
Error Response (400):
{
"status": "error",
"message": "Comment does not belong to this recipe"
}