Welcome to the code repository for Key Value store. The code stored serves the following purposes:
- Provide a rest api for persisting a key value object where key is a string value auto generated and value is a Type of concrete implementations of Item
- Provide a rest api for querying the backend key value store by Id
- Provide a rest api for querying the backend key value store by Name
- Provide a rest api for querying the backend key value store by Kind
- Provides an automated build tool for generating different concrete implementations of type Item. Details below
- Backend store used in Mongo Atlas DB
- Project includes Open API yaml for specifying details . Please check KeyValueOpenAPI.yaml at project root
- Project includes a postman collection KeyValueStore.postman_collection.json for easy execution of API
- download and save in local directory say C:\keyvalue
- open command prompt
- cd C:\keyvalue
- gradle build
- how to run the project gradle bootRun
- We will describe 3 different ways to execute rest api
--- Via Swagger endpoint
- open command prompt and execute the command gradle bootRun
- open a web browser and open http://localhost:9000/swagger-ui/index.html#
- You will find multiple methods exposed under item-db-controller which you can try out
--- Via Post Man Collection
- If you have postman installed in your system, kindly File->import and select the postman collection "KeyValueStore.postman_collection.json"
- Collection via the name KeyValueStore
- You may try out methods /requests specified under the collection
- Do ensure project is in running status
--- Via Curl commands
- Do ensure project is in running status
- Samples provided below
save : curl POST http://localhost:9000/rest/store/ -H "Content-Type: application/json" -d "{"name":"charger","kind":"product"}" -i
getById : curl http://localhost:9000/rest/store/?id=5d224acc-5fa6-4f84-a1e5-08cb6daa4967 -i
getByName: curl http://localhost:9000/rest/store/name?name=hb%20pencil -i
getByKind : curl http://localhost:9000/rest/store/findAll?kind=Lappie -i
delete : curl -X DELETE http://localhost:9000/rest/store/?id=ed91e1d8-176e-4a91-bfcf-1a69899bbb7b
The project comes with a tool for auto generation of source code.
Purpose: If you ever need to create a concrete implementation of com.org.somak.store.keyvalue.dto.Item, eg say Animal , open command prompt
cd directory of the project
gradle run --args='Laptop'
the above method will create 2 classes:
- com.org.somak.store.keyvalue.dto.Laptop
- com.org.somak.store.keyvalue.factory.LaptopFactory
once you create the above, the tool will auto generate the java types in your prject and you can simply go ahead , start the project and run a simple curl command (eg below) to create a key-value pair for Laptop
curl POST http://localhost:9000/rest/store/ -H "Content-Type: application/json" -d "{"name":"DEll","kind":"Laptop"}" -i
#Jacoco test coverage / test reports would be present under build /reports directory to generate jacoco report you may run gradle jacocoTestReport