扫一扫分享
Falcor 是高效的 JavaScript 数据抓取库。
一个模型随处使用:通过一个虚拟 JSON 图可以把所有远程数据源作为一个单独的主模型
绑定云:自动遍历图里面的引用,根据需要进行请求
npm install falcor-router --save
然后安装Express和Falcor Express:
npm install express --save
npm install falcor-express --save
代码示例:
// index.js
const falcorExpress = require('falcor-express');
const Router = require('falcor-router');
const express = require('express');
const 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: () => ({path: ['greeting'], value: 'Hello World'})
}
]);
}));
// serve static files from current directory
app.use(express.static(__dirname + '/'));
app.listen(3000);
手机预览