Simple springboot API for addressBook with redis cache. Supports all REST controllers and have custom error handling for every specific case.
-
Clone the application
git clone https://github.com/ShirishSaxena/AddressBook-SpringBoot-API.git cd AddressBook-SpringBoot-API
-
Create MySQL database
create database assign3rd
-
Change MySQL username and password as per your MySQL installation
-
open
src/main/resources/application.properties
file. -
change
spring.datasource.username
andspring.datasource.password
properties as per your mysql installation
-
-
Run the app
You can run the spring boot app by typing the following command -
mvn spring-boot:run
The server will start on port 7090. And can be changed from application.properties
You can also package the application in the form of a
jar
file and then run it like so -mvn package java -jar target/addressBook-0.0.1-SNAPSHOT.jar
-
Generate Logs (Optional)
pip install pyperclip
Run
sampleGenerator.py
Change these variables as neededcount = 20 # generate count no of random records
It'll generate List of POST req and copy to your clipboard. Finally, paste it on POSTMAN...
* To be added
- Implement findByPhoneNo to GET,PUT,DELETE req.
- Improve queries to saveAll
Assumed that in an addressBook, email and PhoneNo will always be unique. And per record can have atmost 1 phoneNo and Email.
POST Mapping
P100 : firstName is required and can not be null or empty. { "firstName" : "yourName"}
P101 : lastName is required and can not be null or empty. { "lastName" : "yourName"}
P102 : Email is required and can not be null or empty. { "email" : "valid@email"}
P103 : phoneNo is required and can not be null or empty.
P104 : address is required and can not be null or empty.
P111 : Not a valid email.
P112 : Duplicate email found.
P121 : Duplicate PhoneNo found.
PUT Mapping
U100 : Invalid body to update record.
DELETE Mapping
D100 : Parameter not in id or email.
All of the requests made in these screenshot are from remote database with about 200ms ping, so response is slow.
-
Get all records saved in the addressBook.
localhost:7090/api/getAll
-
Get By ID or EmailAddress (Both are Unique field)
localhost:7090/api/get/{parameter}
-
Add single record
localhost:7090/api/ { "firstName" : "firstName", "lastName" : "lastName", "email" : "valid@email", "address" : "Any address???", "phoneNo" : "000000000" }
-
Add multiple records
localhost:7090/api/saveAll [ { "firstName" : "firstName", "lastName" : "lastName", "email" : "valid@email", "address" : "Any address???", "phoneNo" : "000000000" }, { "firstName" : "firstName", "lastName" : "lastName", "email" : "valid@email", "address" : "Any address???", "phoneNo" : "000000000" } ]
```
localhost:7090/api/
```
```
localhost:7090/api/
```