Sample of an application using cloud foundry with a mysql instance bounded.
The program is implementing a Todo List throught a set of rest api
You can get the collection of Todo to do, you can insert, update or delete a new todo item following this curl commands:
You can test with curl the various rest api, for instance
curl http://localhost:8080/todos
will get to the collection showing all the collection elements
this one will create a new element to the collection
curl -H "Content-Type: application/json" -d '{"Topic":"New TodoElem", "Completed":0}' -X POST http://localhost:8080/todos
this one will get an element:
curl http://localhost:8080/todos/1
this one will update an existing element of the collection
curl -H "Content-Type: application/json" -d '{"Id":0,"name":"New TodoElem Updated"}' -X PUT http://localhost:8080/todos
this one will delete a resource
curl -X DELETE http://localhost/todos/1
this one will delete all the collection
curl -X DELETE http://localhost/todos
You need an instance of mysql to run. Create a database and the simple table as defined in the file datastore.sql file
In the file conf specify the dbms parameters (user, password, host, port and database)
Run /bin/project
The server will start listening to port 8080 ready to listen to the curl command as specified above
- Download and install cf-dev https://docs.pivotal.io/pcf-dev/usage.html or create and account at Pivotal Web Service https://run.pivotal.io/
- Download and install the cf client
- Login with cf
cf login -a https://api.dev.cfdev.sh --skip-ssl-validation - cf push on the current project path
- Open the apps manager and login with: admin, admin
https://login.dev.cfdev.sh/home - in services section create a new mysql service and bind it to the current app (todos)
- Do an cf mysql your_mysel_service_name in order to enter to the mysql prompt of the mysq instance now created
- Create database and table as specified in datastore.sql
- Create a binding key, once created have a look at it in order to look to the username/password and host to use
- Replace the info in the conf file of the project and cf push again
- Use https://todos.dev.cfdev.sh/todos and the commands specified before to test teh application using the rest-api
13. Do and cf ssh todos in order to enter the container app and go to /app/logs/mylogger.log in order to debug and see the log of the application if necessary.