Skip to content

Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

Notifications You must be signed in to change notification settings

shirishsaxena/AddressBook-SpringBoot-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AddressBook-SpringBoot-API

Simple springboot API for addressBook with redis cache. Supports all REST controllers and have custom error handling for every specific case.

Setup

  1. Clone the application

    git clone https://github.com/ShirishSaxena/AddressBook-SpringBoot-API.git
    cd AddressBook-SpringBoot-API
  2. Create MySQL database

    create database assign3rd
  3. Change MySQL username and password as per your MySQL installation

    • open src/main/resources/application.properties file.

    • change spring.datasource.username and spring.datasource.password properties as per your mysql installation

  4. 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
  5. Generate Logs (Optional) pip install pyperclip

    Run sampleGenerator.py Change these variables as needed

    count = 20 # generate count no of random records
    

    It'll generate List of POST req and copy to your clipboard. Finally, paste it on POSTMAN...

Updates

* To be added

Further Improvements

  • Implement findByPhoneNo to GET,PUT,DELETE req.
  • Improve queries to saveAll

Assumptions

Assumed that in an addressBook, email and PhoneNo will always be unique. And per record can have atmost 1 phoneNo and Email.

Error codes

   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.

API supports all REST mappings (GET, POST, PUT, DELETE)

All of the requests made in these screenshot are from remote database with about 200ms ping, so response is slow.

GET requests

  • Get all records saved in the addressBook.

     localhost:7090/api/getAll
    

    image

  • Get By ID or EmailAddress (Both are Unique field)

     localhost:7090/api/get/{parameter}
    

    gif

POST requests (with error handling)

  • Add single record

     localhost:7090/api/
     
     {
     	"firstName" : "firstName",
     	"lastName" : "lastName",
     	"email" : "valid@email",
     	"address" : "Any address???",
     	"phoneNo" : "000000000"
     }
    

    image

  • 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"
     }
     
     ]
    

    image

DELETE requests (Support delete by either id or email)

```
localhost:7090/api/
```

image

PUT requests (need id or email to not be null)

```
localhost:7090/api/
```

image

About

Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published