Skip to content

A Java Spring Boot Application that uses both REST and GraphQL

Notifications You must be signed in to change notification settings

MaRwSJ/recipe-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

To run this application: run mvn clean install in terminal and then run the main method in RecipeApiApplication.java located in (Recipe-api/src/main/java/com/example/Recipe_api/RecipeApiApplication.java)

Recipe API (JAva SpingBoot + GraphQL)

Overview:

This Recipe API is a backend service build with Spring Boot and GraphQL that allows users to: - GET - CREATE - UPDATE - DELETE Recipes along with their ingredients.

Goals:

  • To build a Recipe API database using gtaphql in order to gain knowledge with building Java springboot and GraphQL.

  • Build a real world backend application with postgreSQL.

  • Design a Database and create it in postgrSQL.

  • Understand REST vs GraphQL API Design

** note: this project is a work in progress as I am using it to learn about REST and GraphQL using Spring Boot. **

Tech Stack:

  • Spring Boot 3.4.2
  • GraphqL + Codegen (for API Schema)
  • PostgreSQL (Database)
  • InjelliJ IDEA (IDE for development)
  • Maven (dependency management)

Database Design: PostgreSQL

this application will consist of 2 tables in my database:

Tables**

  • Recipe

    • id (UUID) - Primary Key
    • name (String)
    • description (String)
    • instructions (Text)
    • ingredients (One-to-Many Relationship to the ingreidents table)
  • Ingredient

    • id (UUID) - Primary Key
    • name (String)
    • quantity (String)
    • recipe_id (Foreign Key)

Steps Taken For Setup:

1. Created a new Spring Boot project using Spring Initalizer website and added my dependencies:

  • Spring Boot Web
  • SpringBoot GraphQL
  • GraphQL codegen
  • PostgreSQL Driver

2. Added an application.yaml file for connecting to the postgreSQL database:

  • Before this I went into postgres and opened a database and created the tables with the columns i wanted. I used my credentials in the application.yaml file located: src/main/java.com.example.Recipe_api/resources folder.

3. Created Recipe Controller in /src/main/java/com/example/Recipe_api/controller folder

  • Added a simple endpoint that returns "API is working" to test the endpoint

4. Created the models for Recipe and Ingredient - /src/main/java/com/example/Recipe_api/model folder

  • Defined the eneity models - these are the java data version of the tables created in postgres.

5. Created the repositories for these - /src/main/java/com/example/Recipe_api/repository folder

  • Created a repository for Recipe and Ingreidents as this repository will internact with the database.

5. RecipeApiApplication.java: entry point into the Spring Boot App

  • located /src/main/java/com/example/Recipe_api/RecipeApiApplication.java - this is the main method for this whole app

Next Steps: To implement

Create GraphQL schema

Implement a simple query for fetching ingredients

Implment a simple mutation so you can add, update or delete a recipe from the database

Add additonal api endpoints to familarize with REST api Write Unit tests to test each part of my code

About

A Java Spring Boot Application that uses both REST and GraphQL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages