1. Api design in Node
a node file is actually in IFEE that receives some global variables (module,exports,dirname...)
exports.setup = function(){}
is equivalent to
module.exports = {
setup: function(){}
}
sails.js -> closest to rails
express -> abstracts a lot of networking related stuff
express is more configurable sails or loopback is more about conventions
express takes advantage of node's vented i.o. -> register callbacks when a particular cominbation of http verbs and routes are hit
it's a routing library with middleware. that's all that it does
REST :
- stateless
- explicit http words (GET, POST, PUT, DELETE)
- expose directory like url pattern for routes
- transfer JSON and or XML
1. Always model your data first! (a JSON object)
get: ask for something
post: give something
put: update something
delete: delete something
(CRUD operations)
2. Diagram your routes (resources)
e.g.
{
"GET /lions": {
"desc": "returns all lions",
"response": "200 application/json"
"data":[{},{},{}]
},
"GET /lions/:id":{
"desc": "returns one lion represented by its id",
"response":...
}
}