This is a small Spring Boot app that uses java + maven Clever Cloud application type.
This is a RESTful app which is using the MongoDB addon.
As a RESTful you can use HTTP requests like:
GET /users
GET /users/{userId}
POST /users "body": {"firstName":"Robert", "lastName":"Cloud"}
DELETE /users/{userId}
"users":[ { "id":"...", "firstName":"...", "lastName":"..." } ]
MongoDB URI is set in src/main/resources/application.properties
and looks like:
spring.data.mongodb.uri=${MONGODB_ADDON_URI}
Where MONGODB_ADDON_URI
is an environment variable which is specified by MongoDB addon link.
For a maven application on clever, you have to define clevercloud/maven.json
which is containing the maven goals to build and run your app.
{
"build": {
"goal": "package"
},
"deploy": {
"goal": "spring-boot:run"
}
}
Create a clever application using maven, install a MongoDB addon, link it then deploy !
- install dependencies:
mvn install
- tests:
mvn test
- run:
mvn spring-boot:run
Create new user
curl -d '{"firstName":"DUVAL", "lastName":"Alexandre"}' -H "Content-Type: application/json" -X POST http://<appId>.cleverapps.io/users
Get users list
curl -X GET http://<appId>.cleverapps.io/users
Find user by id
curl -X GET http://<appId>.cleverapps.io/users/<userId>
Remove user by id
curl -X DELETE http://<appId>.cleverapps.io/users/<userId>
I wrote an example of test in src/test/java/com/cc/demo/test/UserMongoRepositoryTest.java
which is called during mvn test
.