Skip to content

ruslan-marian/bistro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Recipes API Backend

This is a simple API for recipes and ingredients. The customer could be a French-style bistro.

Quick start

  1. Use Git to clone this repo.
  2. To build the project: ./mvnw clean install.
  3. To serve it: ./mvnw spring-boot:run.
  4. To test: http://localhost:8080.

Project description

The project is built with Spring Boot and these Starters and dependencies:

  1. Web - Full-stack web development with Tomcat.
  2. JPA - Java Persistence API including spring-data-jpa, spring-orm and Hibernate
  3. H2 - H2 database (with embedded support)
  4. DevTools - Spring Boot Development Tools

The embedded database is initialized automatically at startup. This is enabled by placing the data.sql file in the src/main/resources folder.

Spring Boot Development Tools

The development tools are enabled by default. This is done by setting the property spring.h2.console.enabled=true at the file application.properties.

The database can be explored from the H2 console:

  1. To access the database open http://localhost:8080/h2-console.
  2. Make sure H2 console uses JDBC URL jdbc:h2:mem:testdb.
  3. Query the tables ingredient and recipe to see their data.

Testing

The GET method can be tested in a browser. For instance, to get ingredient 1 paste this http://localhost:8080/api/ingredient/1 in the address bar.

Other methods, like POST and PUT can be tested using the Postman API testing tool.
For example, when trying POST with http://localhost:8080/api/ingredient, select the request Body type as raw and change "Text" to "JSON (application/json)" and write the value using this format: {"name"="red wine"}.

In a similar way, to POST a new recipe set a JSON body to {"name": "The Portobello Grilled Steak", "people": 2}.

References

Spring Initializr
Building a RESTful Web Service
Spring Boot and H2 in memory database
Spring Boot Reference Guide
Mapping ManyToMany association table with an extra column

About

Recipes API Backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages