- Notifications
You must be signed in to change notification settings - Fork292
Sample ToDo application (various languages) running on IBM Cloud
License
IBM-Cloud/todo-apps
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The ToDo sample apps are meant to be simple demos of how you can take advantageof Bluemix and a database service. In addition it shows how to take advantageof both thebuilt-in andcommunity buildpacksto deploy your app using whatever runtime you choose.
The ToDo app is pretty simple, it allows you to add an persist ToDos that youneed to get done. As you complete different ToDos you can mark them done andeventually delete them from the list. The ToDos are stored in a database.
All implementations support two different database backends,Mongo DB andCouch DBviaCloudant. If you want to use Cloudant see thesection of this README titled "Couch DB and Cloudant".
The front-end UI for the ToDo app uses a slightly modified version of theBackbone sample fromTodoMVC.com. The main change wasto change thecollections/todo.js
file to not uselocalStorage
,but to instead set theurl
toapis/todos
,so that the ToDos are retrieved from the server instead of from localStorage.
The originalcollections/todo.js
file ishere.
There are various implementation for the back-end of the ToDo app.We have implemented the back-end currently inJava, Node.js, Sinatra, Python, and PHP. If you want to contribute a backendin another language we enchourage you to do. See the "adding new implementations"section.
All of the implementations are similar; they serve up the files in thefrontend
directory as static web resources - html, css, js files. And theyalso expose an api at the uriapi/todos
to query and modify the ToDos.
Note that this isn't really a realistic ToDo app, at present, since it maintainsa global list of Todos that the entire world shares. The intent is just toshow using an existing simple front-end application with a simple databaseback-end. A real example would probably include user authentication, storingToDo's on a per-user basis, etc.
To get the code you can just clone the repo.
git clone git@github.com:IBM-Bluemix/todo-apps.git
The repository contains a directory for each implementation, and thefrontend
directory contains the web resources that are used by eachimplementation.
To run the samples on Bluemix you must have signed up for Bluemix and haveinstalled the Cloud Foundry command line tool. To sign up for Bluemix head tobluemix.net and register.
You can download the Cloud Foundry command line tool by following the steps in theREADME file.
After you have installed the Cloud Foundry command line tool you need to point itat Bluemix so it knows where to deploy the applications. You can do this by running
cf login -a https://api.ng.bluemix.net
This will prompt you to login with your Bluemix user ID and password which is thesame as your IBM ID and password. You should only need to do this once, the commandline tool will remember this information.
Most of the projects use build technologies that are specific to the runtime the ToDoapp is written in to deploy the app to Bluemix (Maven, Rake, Paver, etc). The assumptionis that these are tools developers who are using these runtimes are familiar with.
Under the covers they are using the Cloud Foundry command line to deploy the apps.
The benefit is that you don't need to remember verbose commands (in most cases) andcontinue to use tools you are comfortable with. See the individual runtime folders(java, node, php, python, sinatra) for more details on how to deploy the variousversions.
Feel free to expand upon this project by adding new implementations in yourfavorite runtime or framework. Below is a simple specification you should keepin mind when adding new implementations.
- The server implementation should support GET, POST, PUT, and DELETE.
GET /api/todos
GET ResponseThe response should be a JSON array of all ToDos.
[{"completed":false,"id":"001fbbe7bd708a34624b47526cd6ac89","order":1,"title":"test"},{"completed":false,"id":"4d6153cf4bc3bdaf9c6c7eebf42d67a6","order":2,"title":"1"},{"completed":false,"id":"be3855e004dd5d74c802992c09ea8d28","order":3,"title":"2"},{"completed":false,"id":"e7cb7149098961e5dc182715f1cb0e9d","order":4,"title":"3"},{"completed":false,"id":"9368ccc4629a1c8dfd99a9e741d01c44","order":5,"title":"4"},{"completed":false,"id":"e5752d462b83f13da3d8dced1c15eb43","order":6,"title":"5"}]
POST /api/todos/
POST Body
{"title":"another","order":7,"completed":false}
POST ResponseThe response should be a JSON representation of a ToDo with the id fieldpopulated.
{"completed":false,"id":"f76424cc41f1ee8c2682a37069098794","order":7,"title":"another"}
PUT /api/todos/[id]
PUT Body
{"completed":true,"id":"4d6153cf4bc3bdaf9c6c7eebf42d67a6","order":2,"title":"1"}
PUT ResponseThe response should be a JSON representation of the updated ToDo.
{"completed":true,"id":"4d6153cf4bc3bdaf9c6c7eebf42d67a6","order":2,"title":"1"}
DELETE /api/todos/[id]
DELETE ResponseThe response should be a 204.
- The Mongo implementation should use a collection called "todos".
- You should create a Mongo DB service with the name "todo-mongo-db" or "todo-compose-mongo-db", depending on which Mongo provider you choose.
It will most likely be useful to have a local Mongo DB server for testingwhen adding new implementations.
See the Mongo DBinstall instructionsfor your platform to install a local Mongo DB server.
You should create a Cloudant service with the name "todo-couch-db".
The name of the Couch DB / Cloudant database to use is "bluemix-todo".
View
The application code should create a view document, if one doesn't already exist,in the bluemix-todo database with the following JSON.
{ views: { allTodos: { reduce: "_count", map: "function(doc){if(doc.title && doc.completed != null){emit(doc.order,{title: doc.title,completed: doc.completed})}}" } }}
It will most likely be useful to have a local Couch DB server for testingwhen adding new implementations.
Relax, this is very easy!
Head over to the official home of CouchDB -http://couchdb.apache.org/ - andclick the red "DOWNLOAD" link. Follow the instructions to download a verisonof CouchDB for your platform.
When running the Mac version of CouchDB, you'll have a menu bar tool-button you canuse to start and manage the database.
The implementations will run locally as long as the CouchDB server is running.By default the Couch DB will be running athttp://127.0.0.1:5984.