This is a simple API for recipes and ingredients. The customer could be a French-style bistro.
- Use Git to clone this repo.
- To build the project:
./mvnw clean install
. - To serve it:
./mvnw spring-boot:run
. - To test:
http://localhost:8080
.
The project is built with Spring Boot and these Starters and dependencies:
- Web - Full-stack web development with Tomcat.
- JPA - Java Persistence API including spring-data-jpa, spring-orm and Hibernate
- H2 - H2 database (with embedded support)
- 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.
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:
- To access the database open
http://localhost:8080/h2-console
. - Make sure H2 console uses JDBC URL
jdbc:h2:mem:testdb
. - Query the tables
ingredient
andrecipe
to see their data.
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}
.
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