π Introduction
If you're a Java developer looking for a practical way to integrate Azure CosmosDB into your Spring Boot API, this open-source project is for you! π
I built this project to help developers who need a working example of using Spring Boot with CosmosDB. Whether you're learning NoSQL databases, working with Azure Cloud, or just want to see how CosmosDB works in a real-world application, this repo will help you.
π― Why I Built This Project
While working with CosmosDB, I realized that many developers struggle with:
β
Setting up CosmosDB in a Spring Boot application
β
Configuring Reactive Spring Data CosmosDB properly
β
Handling CRUD operations in a scalable way
So, I built this fully working API with CosmosDB to make it easy for developers to get started. The project is free, open-source, and easy to install!
π Features
β
Spring Boot + Reactive CosmosDB Integration
β
CRUD API for Users (Create, Read, Update, Delete)
β
Pagination & Querying CosmosDB
π οΈ Prerequisites
Before you begin, ensure you have the following installed:
βοΈ Java: Version 21 or later
βοΈ Maven: Version 3.9.9 or later
βοΈ Azure Subscription: Required for creating & accessing Azure CosmosDB
βοΈ Azure CLI (az): Required for managing CosmosDB
π How to Install and Run Locally
Follow these steps to clone and run the project:
# 1οΈβ£ Clone the Repository
git clone https://github.com/coumarane/spring-boot-cosmosdb.git
cd spring-boot-cosmosdb
# 2οΈβ£ Build the Project
./mvnw clean install
# 3οΈβ£ Run the Application
./mvnw spring-boot:run
π Configure Azure CosmosDB Connection
Create a CosmosDB account before continuing with the further steps.
Use a Real CosmosDB Instance
Update an application.properties file in src/main/resources/ :
azure.cosmos.connection-string=<<PRIMARY CONNECTION STRING>>
azure.cosmos.database=<<COSMOSDB DATABASE>>
π‘ API Endpoints & Testing
Once the application is running, you can test the APIs:
β
Get All Users
curl -i http://localhost:8080/users
β
Create a New User
curl -i -X POST -H "Content-Type: application/json" \
-d '{"email":"john@gmail.com", "firstName":"John", "lastName":"Doe", "city":"New York"}' \
http://localhost:8080/users
β
Update a User
curl -i -X PUT -H "Content-Type: application/json" \
-d '{"email":"john_updated@gmail.com", "firstName":"John", "lastName":"Doe", "city":"Los Angeles"}' \
http://localhost:8080/users/{USER ID}
β
Delete a User
curl -i -X DELETE http://localhost:8080/users/{USER ID}
π GitHub Repo
π Check out the full code here:
β‘οΈ GitHub Repository: https://github.com/coumarane/spring-boot-cosmosdb
If you find this useful, please β star the repo and share it with others! ππ
π Final Thoughts
This project is open-source and meant to help developers quickly integrate CosmosDB with Spring Boot. If you're working on a cloud-based, NoSQL application, this will save you a lot of setup time!
Let me know what you think in the comments! π¬
π Happy Coding!
Top comments (0)