Skip to content

wichon/spring-boot-petstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-boot-petstore

A dummy pet store to play with Spring Boot and Spring Cloud frameworks

Features:

  • Jetty server instead of the default one used by spring boot (tomcat)
  • Database Access using an in-memory embeded data base (H2DB via a JPA repository implementation)
  • Data Caching using the default spring cache storage (ConcurrentHashMap)
  • Distributed configuration using Spring Cloud Config Server and Client
    • Spring Cloud Config server source is a git repo (config files by profile in this-repo/config)

Services

Config Server

A distributed config server for the petstore inventory app

run

cd config-server/
gradle build
java -jar build/libs/config-0.0.1-SNAPSHOT.jar

Petstore Inventory

A dummy petstore that lets you add/update/delete pets to the inventory, find them by type, or list them all

run

cd petstore-inventory/
gradle build
java -jar build/libs/inventory-0.0.1-SNAPSHOT.jar

pet data model

Pet entities are defined in the petstore-inventory project under Pet.java

Entity can be mapped to the following json structure:

{
  "id": "1"
  "name": "rose", 
  "type": "dog", 
  "color": "white"
}

endpoints

/ (index, GET)

Returns a json collection of all available pets, endpoint is cached.

/find/{type} (GET)

Returns a json collection of {type} available pets, endpoint is cached.

/add (POST)

Receives a json entity (in the request body) defining a new pet, id is autogenerated by the data repository so there is no need to include the id in the object. Clears cache for /find and / endpoints.

Curl example:

curl -X POST -H "Content-Type: application/json" -d '{"name": "rose", "type": "dog", "color": "white"}' localhost:8000/add

/add-bulk (POST)

Receives a collection of json entities (in the request body) defining a set of new pets, id is autogenerated by the data repository so there is no need to include the ids in the collection. Clears cache for /find and / endpoints.

Curl example:

curl -X POST -H "Content-Type: application/json" -d '[{"name": "jose", "type": "cat", "color": "white"}, {"name": "steve", "type": "dog", "color": "brow"}, {"name": "hector", "type": "snake", "color": "green"}]' localhost:8000/add-bulk

/update (POST)

Receives a json entity (in the request body) to modify an existing pet all attributes of the pet should be set, including the id. Clears cache for /find and / endpoints.

Curl example:

curl -X POST -H "Content-Type: application/json" -d '{"id": 1, "name": "rosa", "type": "dog", "color": "white"}' localhost:8000/update

/delete/{id} (POST)

Removes a pet from the inventory by its id. Clears cache for /find and / endpoints.

Curl example:

curl localhost:8000/delete/6

/info (GET)

Returns the petstore owner information associated to this petstore inventory. This information is retrieved via the configuration server and is stored in the config/ folder.

There are two files, one per application profile (north and south), that can be changed in the bootstrap.yml of the petstore-inventory app.

/info/owner (GET)

Returns owner name from the information stored in the configuration server.

/info/address (GET)

Returns address from the information stored in the configuration server.

/info/phone (GET)

Returns phone from the information stored in the configuration server.

About

A dummy pet store to play with Spring Boot framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages