- Provide 2 http endpoints that accepts JSON base64 encoded binary data on both endpoints
- /v1/diff//left and /v1/diff//right
- The provided data needs to be diff-ed and the results shall be available on a third end point
- /v1/diff/
- The results shall provide the following info in JSON format
- If equal return that
- If not of equal size just return that
- If of same size provide insight in where the diffs are, actual diffs are not needed. So mainly offsets + length in the data
The input will be a JSON format which will contain a Base64 encoded string. Below are sample Request and Response body :
{
"data" : "dGVzdGluZyB0aGUgYmFzZTY0"
}
{
"message" : "Json Data on the Left side saved successfully"
}
We will save the ID and its corresponding left and right side into database. When client will call the /v1/diff/, We will use the same id to retrieve the left and right side of data from the database and return the result.
- Java 8
- Spring Boot
- Spring Data
- Spring JPA
- H2 Database
- Maven
- Swagger 2
- Junit & Mockito
Before being able to build he code you need:
- Maven 3.3+
- Java 1.8
After you have installed Building requirements tool:
cd scalable-web-json-comparator/scalable-web
mvn test
cd scalable-web-json-comparator/scalable-web
mvn javadoc:javadoc
This will create java docs at below location :
cd scalable-web-json-comparator/scalable-web/target/site/apidocs/
git clone https://github.com/saurabhoza/scalable-web-json-comparator.git
cd scalable-web-json-comparator/scalable-web
mvn package
java -jar target/scalable-web-1.0.jar
- POST /v1/diff/{id}/left
- POST /v1/diff/{id}/right
- GET /v1/diff/{id}
Request Body
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"data": "dGVzdGluZyB0aGUgYmFzZTY0" \
}' 'http://localhost:8080/v1/diff/1/left'
Response Body
{
"message": "Json Data on the Left side saved successfully"
}
Request Body
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"data": "dGVzdGluZyB0aGUgYmFzZTY0" \
}' 'http://localhost:8080/v1/diff/1/right'
Response Body
{
"message": "Json Data on the Right side saved successfully"
}
Request Body
curl -X GET --header 'Accept: application/json' 'http://localhost:8080/v1/diff/1'
Response Body
{
"message": "Left and Right side of Json data is equal."
}
- Default host: http://localhost:8080
- This project is using Swagger2 documentation:
http://localhost:8080/v2/api-docs - JSON format of rest documentation http://localhost:8080/swagger-ui.html - UI representation of rest documentation
- Solution was created;
- Unit tests and Integration tests were created with 97% of code coverage. Code coverage path : https://github.com/saurabhoza/scalable-web-json-comparator/blob/master/Documents/code-coverage-reports/index.html
- Project is built with zero bugs and Vulnerabilities in Sonar. Sonar Dashboard : https://sonarcloud.io/dashboard?id=scalable-project
- Dockerizing would be nice, it allows us to test our application across to multiple instances.
- Distributed Cache(Redis) would need if we run application across to multiple instances.
- Authentication will restrict unauthorizes access to this API.