fetching
v0.0.2
Published
Fetching strategies for nodejs.
Downloads
26
Readme
Fetching
_ = require 'underscore'
pagecontents = [
{ path: '/', contents: 'home' }
{ path: '/test', contents: 'test' }
{ path: '/about', contents: 'about' }
]
app.fetch.bind 'pagecontents', 'bypath', (app, params, cb) ->
cb _(pagecontents).find (page) -> page.path is params.path
app.fetch.bind 'pagecontents', 'search', (app, params, cb) ->
cb _(pagecontents).filter (page) ->
(page.path.startswith params.term) or (page.contents.contains term)
What is the problem?
When writing systems the way data is retrieved is not related to the logic. As a result it's useful to have some form of separation. Additionally how the information is presented is not important to how the data is retrieved.
How fetching solves this problem
- A clear separation of where information comes from is provided
app.fetch
provides an interface to register and retrieve information. - The results of this information can be made available as json, xml, or any other representation.
- Metadata is kept for debugging purposes.
Goals
- Simple
- One concept multiple specifications