Falcor - 高效从服务器返回数据的 Javascript 库


Apache-2.0
跨平台
JavaScript

软件简介

Falcor 是高效的 JavaScript 数据抓取库。

  • 一个模型随处使用 :通过一个虚拟 JSON 图可以把所有远程数据源作为一个单独的主模型

  • 数据即是 API :类似 JavaScript 路径语法,可以很简单的访问数据。

  • 绑定云 :自动遍历图里面的引用,根据需要进行请求

代码示例:

// index.js
var falcorExpress = require('falcor-express');
var Router = require('falcor-router');
var express = require('express');
var app = express();
app.use('/model.json', falcorExpress.dataSourceRoute(function (req, res) {
  // create a Virtual JSON resource with single key ("greeting")
  return new Router([
    {
      // match a request for the key "greeting"    
      route: "greeting",
      // respond with a PathValue with the value of "Hello World."
      get: function() {
        return {path:["greeting"], value: "Hello World"};
      }
    }
  ]);
}));
// serve static files from current directory
app.use(express.static(__dirname + '/'));
var server = app.listen(3000);