Skip to content

A Java Spring Boot API to support an Android app designed to help users manage their pantry and discover recipes based on available ingredients.

Notifications You must be signed in to change notification settings

Candlelight-apps/stocknroll-backend

Repository files navigation

Stock'n'Roll API - README

Introduction

This project is a Spring Boot application that consumes the Spoonacular API to provide food-related data such as recipes and ingredients. The API interacts with Spoonacular to retrieve, process, and serve data to clients. This API serves our Stock’n’Roll Android App. This README will guide you through the setup, configuration, and usage of the project.

Prerequisites

Before starting, ensure you have the following installed:

  • Java 21
  • Maven 3.6.3 or higher
  • Spring Boot 3.3.4 or higher
  • A Spoonacular API Key (You can obtain it by signing up at Spoonacular)

Optional:

  • PostgreSQL
  • AWS-RDS
  • PgAdmin
  • Postman

Features

  • Fetch recipes by ingredients.
  • Fetch recipes by cuisine,diet & intolerances.
  • Get detailed information about recipes, from the source URL.
  • Add ingredients that match Spoonacular and retrieve or delete ingredients from the database.
  • Add or delete recipes from favourites
  • Handle different endpoints to make the Spoonacular API easier to work with in a Spring Boot project.

Getting Started

  1. Clone the Repository

git clone https://github.com/Candlelight-apps/stocknroll-backend.git

  1. Setup the Spoonacular API Key
  • First obtain your API Key by signing up at Spoonacular
  • Create a config directory from root folder.
  • Create apikey.properties under it
  • Paste it in your apikey.properties ->

API_KEY= Your-spoonacular-ApiKey

  1. Application.properties

Create the following .properties files under resources folder : src/main/resources/

application.properties

spring.application.name=stocknroll-backend

spring.profiles.active=h2 <change this to your corresponding .properties file name containing your desired db connection config>

#Health endpoint

management.endpoints.enabled-by-default=false management.endpoint.health.enabled=true management.endpoints.web.exposure.include=health

#Enable Swagger UI

springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true

H2

application-h2.properties

#H2 database connection settings

spring.datasource.url=jdbc:h2:mem:stocknrolldb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.datasource.platform=h2 server.address=0.0.0.0 server.port=8080

#Hibernate settings (optional but often used)

spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=update ##or create-drop, create, validate (based on your use case)

#Enable H2 Console (optional, for debugging)

spring.h2.console.enabled=true spring.h2.console.path=/h2-console

PostgreSQL

Create the following .properties file if using PostgreSQL database and set spring.profiles.active=dev in your application.properties file Application-dev.properties

spring.datasource.url=jdbc:postgresql://localhost:5432/YOUR_DATABASE_NAME spring.datasource.driverClassName=org.postgresql.Driver spring.datasource.username=YOUR_DB_USERNAME spring.datasource.password=YOUR_DB_PASSWORD

#Hibernate settings (optional but often used)

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true logging.level.org.hibernate.SQL=DEBUG

AWS RDS

Create the following .properties file if using AWS-RDS and set spring.profiles.active=aws in your application.properties file

application-aws.properties

spring.datasource.url=jdbc:postgresql://YOUR_AWS_RDS_URL/DATABASE_NAME spring.datasource.username=YOUR_DATABASE_NAME spring.datasource.password=YOUR_DATABASE_PASSWORD spring.jpa.database=postgresql spring.jpa.hibernate.ddl-auto=update

  1. Once all 3 steps are completed you may run the application.

SWAGGER

You can use Postman/Swagger to test the endpoints. To access Swagger open link in web after running the application. http://localhost:8080/swagger-ui/index.html

H2-CONSOLE

You may use PgAdmin if using PostgreSQL or AWS-RDS. To access H2 console open link in the web after running the application. http://localhost:8080/h2-console/

END POINTS

BASE_URL: /api/v1/stocknroll/

JSON format for request body:

{
"name": "pork",
"category": "meat&seafood",
"quantity": 1,
"expiryDate": "2024-10-20",
"imageUrl": ""
}

JSON format for request body:

{ "recipeId": 0,
"title": "string",
"readyInMinutes": 0,
"sourceUrl": "string",
"image": "string",
"favourite": true
}
  • GET: recipesByIngredient:

Returns max 10 recipes from Spoonacular API http://localhost:8080/api/v1/stocknroll/recipes/ingredient?values=egg,pork

  • GET: recipesByCriteria:

Returns maximum 10 recipes from Spoonacular API http://localhost:8080/api/v1/stocknroll/recipes/criteria?cuisine=JAPANESE&diet=&intolerances=seafood

Recipes Returned:

[
    {
        "id": 652078,
        "title": "Miso Soup With Thin Noodles",
        "image": "https://img.spoonacular.com/recipes/652078-312x231.jpg",
        "imageType": "jpg",
        "readyInMinutes": 45,
        "sourceUrl": "https://www.foodista.com/recipe/BYJ4Q2M5/miso-soup-with-thin-noodles"
    },
    {
        "id": 648506,
        "title": "Japanese Sushi",
        "image": "https://img.spoonacular.com/recipes/648506-312x231.jpg",
        "imageType": "jpg",
        "readyInMinutes": 45,
        "sourceUrl": "https://www.foodista.com/recipe/ZHC2WBHW/japanese-sushi"
    }
]

About

A Java Spring Boot API to support an Android app designed to help users manage their pantry and discover recipes based on available ingredients.

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages