Making a To-Do List With flatiron.js (Story 3)
This post continues the creation of a to-do list with flatiron.js.
Previous Stories in this Series
Oooh, a model. Finally! Let’s use resourceful to define this ToDo
model.
Turns out that the most recently released version of resourceful suffers
from some bugs, too. So, modify your package.json
file to read
1 | { |
and run the commands
1 | npm uninstall resourceful |
resourceful - A storage agnostic resource-oriented ODM for building prototypical models with validation and sanitization.
That’s quite a mouthful. In short, resourceful allows us to define prototypes that will ensure that the properties have values of the correct type assigned to them and other simple validations.
For us, though, we just want a pretty simple Task class that has an
identifier, some text to describe the task, and a created date. I think would
fit the bill, pretty well. At the top of our server.js
file, we should
require
resourceful and define our Task prototype.
1 | // server.js |
Now, down after the definition for GET, I will define my POST logic. I will
need to parse the body of the post, so I will include a
qs = require('querystring')
at the top of the file.
1 | app.router.post('/', function() { |
Not bad at all.