Spring Boot Microservice to serve data using REST and MongoDB
The database has already been set up on MongoDB Cloud Atlas: Steps of setting the Database:
- Connect to MongoDB Atlas with your CLI (details for my AWS instance can be found in details below).
- Create Database (megaman) with the below command:
use megaman
- Create Collection bosses with the below command:
create collection("bosses")
- add documents to the bosses collection:
db.bosses.insertMany([{"name": "Man", "weapon": "Rolling Cutter", "weakness": "Super Arm" }, {"name": "Guts Man", "weapon": "Super Arm", "weakness": "Hyper Bomb" }, {"name": "Fire Man", "weapon": "Fire Wave", "weakness": "Ice Slasher" } ]); db.bosses.insertMany([{"name": "Super Siyaan", "weapon": "Rolling Cutter", "weakness": "Gohan" }, {"name": "Gohan", "weapon": "Hyper Bomb", "weakness": "Fire Wave" }, {"name": "Fire Girl", "weapon": "Fire Wave", "weakness": "Ice Slasher" } ]); db.bosses.insertMany([{"name": "Arrow", "weapon": "bow and Arrow", "weakness": "Fire Wave" }, {"name": "Aparichit", "weapon": "Dagger", "weakness": "Ambi" }, {"name": "Ambi", "weapon": "Rules and Law", "weakness": "Nandini" } ]);
- check the added documents via the command below:
db.bosses.find().forEach(prinjson)
- Pull the code to your local repository and import into your IDE.
- Do maven updated on the project.
- Run the spring boot project.
Instance runs on Port : 8080
Below is the list of APIs provided by the project:
Request Method | ----------------------- Request Endpoint ----------------------------------- |
---|---|
---- GET ----- | http://localhost:8080/megaman/bosses/{id} |
---- GET ----- | http://localhost:8080/megaman/bosses/all |
---- GET ----- | http://localhost:8080/megaman/bosses/name/{name} |
---- GET ----- | http://localhost:8080/megaman/bosses/weapon/{weapon} |
---- GET ----- | http://localhost:8080/megaman/bosses/weakness/{weakness} |
---- GET ----- | http://localhost:8080/megaman/bosses/weapon/{weapon}/and/weakness/{weakness} |
---- GET ----- | http://localhost:8080/megaman/bosses/weapon/{weapon}/or/weakness/{weakness} |
---- GET ----- | http://localhost:8080/megaman/bosses/weakness/{weakness}?order=desc |
---- PUT ----- | http://localhost:8080/megaman/bosses/update/{name} |
---- POST ---- | http://localhost:8080/megaman/bosses/update/{name} |
---- DELETE -- | http://localhost:8080/megaman/bosses/update/{name} |
MongoDB Cloud Atlas Details:
Cluster: AWS North Verginia
URI: mongodb+srv://devcluster-pybq6.mongodb.net/megaman
DB: mageman
Note- All credentials have been added in the application.properties file to support quick connection.