Recipe rest api that includes CRUD (Create, Read, Update, Delete) and getByMultipleCriteria operations using spring boot and mongo DB.
GOTO > ~/absolute-path-to-directory/recipe-service
and try below command in terminal
mvn spring-boot:run
it will run application as spring boot application
or
mvn clean install
it will build application and create jar file under target directory
Run jar file from below path with given command
java -jar ~/path-to-recipe-service/target/recipe-service-0.0.1-SNAPSHOT.jar
Below are the model classes which we will store in MongoDB and perform database operations.
public class Recipe {
@Id
private String id;
private String name;
private String instructions;
private int numberOfServing;
private List<Ingredient> ingredients;
}
public class Ingredient {
private String name;
private String amount;
boolean isVegetarian;
}
HTTP Method | URL | Description |
---|---|---|
GET |
http://localhost:8080/ | Root page |
GET |
http://localhost:8080/swagger-ui/index.html | Swagger UI page |
HTTP Method | URL | Description |
---|---|---|
POST |
http://localhost:8080/api/v1/recipes | Create new Recipe |
PUT |
http://localhost:8080/api/v1/recipes/{id} | Update Recipe by ID |
GET |
http://localhost:8080/api/v1/recipes/{id} | Get Recipe by ID |
DELETE |
http://localhost:8080/api/v1/recipes/{id} | Delete Recipe by ID |
GET |
http://localhost:8080/api/v1/recipes?instructionsLike={instructionsLike}&numberOfServing={numberOfServing}&ingredientIncluded={ingredientIncluded}&ingredientExcluded={ingredientExcluded}&isVegetarian={isVegetarian}&pageNumber={pageNumber}&pageSize={pageSize} | Get Recipes by criteria with Paging.If there is no criteria then all recipes will be returned. |
```
{
"name": "Chicken with the onion",
"instructions": "Bake in the oven",
"numberOfServing": 2,
"ingredients": [
{
"name": "chicken",
"amount": "100g",
"vegetarian": false
},
{
"name": "onion",
"amount": "2",
"vegetarian": true
},
{
"name": "potatoes",
"amount": "1",
"vegetarian": true
}
]
} ```