Skip to content

DanielePalaia/cf-mysql-example

Repository files navigation

Introduction

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


Running locally

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

Running on Cloud Foundry

  1. 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/
  2. Download and install the cf client
  3. Login with cf
    cf login -a https://api.dev.cfdev.sh --skip-ssl-validation
  4. cf push on the current project path
  5. Open the apps manager and login with: admin, admin
    https://login.dev.cfdev.sh/home
  6. in services section create a new mysql service and bind it to the current app (todos)
  7. Do an cf mysql your_mysel_service_name in order to enter to the mysql prompt of the mysq instance now created
  8. Create database and table as specified in datastore.sql
  9. Create a binding key, once created have a look at it in order to look to the username/password and host to use
  10. Replace the info in the conf file of the project and cf push again
  11. 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.

About

example on how to create a cf app with mysql

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages