Spring Boot Rest Api
This project contains the api for thefoodu
Table of Contents
Tools
You will need:
- Maven as your build tool
- Your favorite IDE
- JDK 1.8+
- PostgreSQL
Table of Contents
Dependencies
You will need:
- Spring Data JPA
- PostgreSQL Connector
- Spring WEB
- JUnit
- JUnit Vintage Engine
- Spring Boot Test Starter
- Spring Boot Maven Plugin
Getting Started
First, clone the project:
$ https://github.com/Lenarty/java.git
Second, open the project using your favorite IDE and install all the listed dependencies above and you should be able to run the application.
If everything works, you should see an Index Page here.
Database
- Create a PostgreSQL database using the thefoodu.sql script provided in the root folder.
- Add credentials to /src/main/resources/application.properties
The default ones are:
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/thefoodu
spring.datasource.username=postgres
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
REST Endpoints
Company Endpoints
Get all companies
- URL
localhost:8080/companies
, METHOD = GET
Save a company
- URL
localhost:8080/company
, METHOD = POST, expects JSON body (only company_name is required)
Find company by id
- URL
localhost:8080/company/{id}
, METHOD = GET
Update Company by id
- URL
localhost:8080/company/{id}
, METHOD = PUT, expects JSON body (id must be the same as previous and company_name can be modified)
Delete a company
- URL
localhost:8080/company/{id}
, METHOD = DELETE
Food Endpoints
Get all foods
- URL
localhost:8080/foods
, METHOD = GET
Save food
- URL
localhost:8080/food
, METHOD = POST, expects JSON body (only food_name is required)
Find food by id
- URL
localhost:8080/food/{id}
, METHOD = GET
Update Food by id
- URL
localhost:8080/food/{id}
, METHOD = PUT, expects JSON body (id must be the same as previous and food_name can be modified)
Delete a company
- URL
localhost:8080/food/{id}
, METHOD = DELETE
Pizza Endpoints
This process is the same for other foods as well
Get all pizzas
- URL
localhost:8080/pizzas
, METHOD = GET
Save a pizza
Before saving pizza first you have to insert food and than to save the food id on this table
- URL
localhost:8080/pizza
, METHOD = POST, expects JSON body (pizza_name, food_name is required)
Find pizza by id
- URL
localhost:8080/pizza/{id}
, METHOD = GET
Check if pizza exists by id
- URL
localhost:8080/pizza/{id}
, METHOD = GET
Delete a pizza
- URL
localhost:8080/pizza/{id}
, METHOD = DELETE