Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-layer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-layer

Data layer for nodejs apps. Provides a internal url interface to grab data.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Data Cache Layer

Your routes shouldn't need to know where data is coming from. You should be able to swap out data sources in a relatively easy manner and still have your websites templates render the exact same way. You should be able to connect the same data to different output formats with ease.

This module provides a way to access your data through internal routes and provides the ability to cache the data. It also provides a template rendering controller and JSON rendering controller.

addRoute

Add a handler for the specified url.

  • route -- internal url
  • handler -- function to grab the requested data
  • ttl -- cache time to live

hander -> function(req, callback)

  • req -- is the request object. Currently only url and params are set.
  • callback -- function to call when the data is retrieved

Example

addRoute('blog/:slug', function(req, cb) {
  getBlogPost(req.params.slug, cb)
})

compositeRoute

Helper to easily compile several routes into one object

  • route -- internal url
  • dependencies -- key value pairs. Key -> dependent url, Value -> key to put data in the returned object.

Example

compositeRoute('blog/:slug/data',
  { 'blog/:slug': 'blogPost'
  , 'blog/:slug/comments': 'comments'
  })
// Generates
// { blogPost: blogPostData
// , comments: commentData
// }

getData

Get data from specified route.

  • route -- the url to grab
  • callback -- callback to call with err or data when data is retrieved.

Example

getData('blog/first-post', function(err, post) {
  if (err) return handleErr(err)
  doSomethingBlogPost(post)
})

connectDataTemplate

External url handler that will render a template with the data result from an internal url

  • dataRoute -- Internal route to get data from
  • template -- Template to render

Example

app.get('/blog/:slug', connectDataTemplate('blog/:slug/data', 'blogPost'))

connectJSONTemplate

External url handler that gives JSON output of internal url data

  • dataRoute -- Internal route to get data from

Example

app.get('/api/blog/:slug/comments', connectJSONTemplate('blog/:slug/comments'))

FAQs

Package last updated on 04 Sep 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc