在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Netflix/falcor开源软件地址:https://github.com/Netflix/falcor开源编程语言:JavaScript 99.9%开源软件介绍:Falcor2.02.0 is the current stable Falcor release. 0.x and 1.x users are welcome to upgrade. RoadmapIssues we're tracking as part of our roadmap are tagged with the roadmap label. They are split into enhancement, stability, performance, tooling, infrastructure and documentation categories, with near, medium and longer term labels to convey a broader sense of the order in which we plan to approach them. Getting StartedYou can check out a working example server for Netflix-like application right now. Alternately, you
can go through this barebones tutorial in which we use the Falcor Router to
create a Virtual JSON resource. In this tutorial we will use Falcor's express
middleware to serve the Virtual JSON resource on an application server at the
URL Creating a Virtual JSON ResourceIn this example we will use the falcor Router to build a Virtual JSON resource
on an app server and host it at {
"greeting": "Hello World"
} Normally, Routers retrieve the data for their Virtual JSON resource from backend datastores or other web services on-demand. However, in this simple tutorial, the Router will simply return static data for a single key. First we create a folder for our application server. $ mkdir falcor-app-server
$ cd falcor-app-server
$ npm init Now we install the falcor Router. $ npm install falcor-router --save Then install express and falcor-express. Support for restify is also available, as is support for hapi via a third-party implementation. $ npm install express --save
$ npm install falcor-express --save Now we create an // 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); Now we run the server, which will listen on port $ node index.js Retrieving Data from the Virtual JSON resourceNow that we've built a simple virtual JSON document with a single read-only key
Create an <!-- index.html -->
<html>
<head>
<!-- Do _not_ rely on this URL in production. Use only during development. -->
<script src="https://netflix.github.io/falcor/build/falcor.browser.js"></script>
<!-- For production use. -->
<!-- <script src="https://cdn.jsdelivr.net/falcor/{VERSION}/falcor.browser.min.js"></script> -->
<script>
var model = falcor({
source: new falcor.HttpDataSource("/model.json"),
});
// retrieve the "greeting" key from the root of the Virtual JSON resource
model.get("greeting").then(function (response) {
document.write(response.json.greeting);
});
</script>
</head>
<body></body>
</html> Now visit
Steps to publish new version
Additional Resources
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论