Corporative Country is a simple microservice demo application created with Spring Boot and MondoDB for consulting country data such as name, calling code and flag icon.
This project supports a case study that aims to show the difficulty of developing a microservice when Spring Boot is chosen for its construction.
- Apache Maven 3.6.2 or higher
- JDK 8 or higher
- Git GUI for GitHub Client
- MongoDb
You can use MongoDB Community Server or MongoDb Atlas (Cloud). I used MongoDb Atlas to create the database. You can create the user database as 'app-user-ms-country' and the database name as 'corporative' and you won’t have to change these properties on the application.properties file.
Clone the repo, I used GUI Client
git clone https://github.com/aliothbl/corporative-ms-country.git
In the file 'application.properties' configure the MongoDb.
corporative.ms.country.app-db-user=${APP_DB_USER:<user>}
corporative.ms.country.app-db-password=${APP_DB_PASSWORD:<passoword>}
corporative.ms.country.db-server=${DB_SERVER:<database server>}
corporative.ms.country.db-name=${DB_NAME:<database name>}
If you want start the microservice in specific port, please change it.
server.port=${SERVER_PORT:8080}
1 - Go to the destination folder
cd /path/to/root-project-folder
2 - Execute the maven command
mvn clean install
3 - Start the microservice
java -jar target/ms-country.jar
Access the Spring Boot Actuator
The response must be:
{
"status":"UP",
"components":{
"diskSpace":{
"status":"UP",
"details":{
"total":402672611328,
"free":278237704192,
"threshold":10485760,
"exists":true
}
},
"mongo":{
"status":"UP",
"details":{
"version":"4.4.6"
}
},
"ping":{
"status":"UP"
}
}
}
Open you browser in 'http://localhost:8080/swagger-ui.html#' or click here.
Using the resource 'POST /v1/corporative/countries' to add your first country to the database with the data below:
{
"code": "+55",
"simpleName": "Brasil",
"fullName": "República Federativa do Brasil",
"flagImageUrl": "https://s3.amazonaws.com/media.latourtec.com/img/br-flag-4x3.svg"
}
The response body must be:
{
"metadata": {},
"data": {
"code": "+55",
"simpleName": "Brasil",
"fullName": "República Federativa do Brasil",
"flagImageUrl": "https://s3.amazonaws.com/media.latourtec.com/img/br-flag-4x3.svg",
"uuid": "60b4c112442d2d6544e1da64"
}
}
And the response headers must be:
accept-language: en-US, pt-BR, es-ES
connection: keep-alive
content-language: en-US
content-type: application/json
date: Mon, 31 May 2021 10:57:22 GMT
keep-alive: timeout=60
transfer-encoding: chunked
vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
How do I install Java
Installing Apache Maven
GUI Client
Install MongoDB