Code Monkey home page Code Monkey logo

falcor.net's Introduction

Falcor.NET Build status NuGet package version Coverity

Gitter

What is Falcor?

Falcor is an approach pioneered by Netflix that enables you to quickly build a data-driven APIs that deliver efficient payloads to a variety of client form factors, and is able to adapt quickly to changing data access patterns as your application evolves.

Falcor provides many of the benefits of both REST and RPC, while addressing shortcomings these approaches face when building modern web applications.

Release Status: Developer Preview

Falcor.NET will remain in developer preview until a stable client and server reference version is released from Netflix all baseline functionality is implemented. Follow progress on this GitHub issue: falcordotnet#1

Getting Started

To get started with Falcor.NET, follow these steps:

  1. In your ASP.NET web project, install the Falcor.Server.Owin NuGet package:
PM> Install-Package Falcor.Server.Owin -Pre
  1. Create your application router to match paths to a virtual JSON Graph model:
public class HelloWorldRouter : FalcorRouter
{
    public HelloWorldRouter()
    {
        // Route to match a JSON path, in this case the 'message' member
        // of the root JSON node of the virtual JSON Graph
        Get["message"] = async _ =>
        {
            var result = await Task.FromResult(Path("message").Atom("Hello World"));
            return Complete(result);
        };
        // Define additional routes for your virtual model here
    }
}

Note: For a more realistic example router, see the example Netflix router which is part of Falcor.Examples.Netflix.Web project that you can run yourself to see the router in action.

  1. In your OWIN startup class, configure your Falcor.NET router endpoint:
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseFalcor("/helloWorldModel.json", routerFactory: config => new HelloWorldRouter());
        ...
    }
}

If you are using IIS (and for most development environments), ensure the web.config has a similar handler configured for your model endpoint:

<system.webServer>
  <handlers>
    <add name="NetflixFalcorModelHandler" path="model.json" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
  </handlers>
</system.webServer>
  1. Using falcor.js in your client, create a new Falcor model, specifying the URL of your new endpoint for your datasource:
var model = new falcor.Model({
  source: new falcor.HttpDataSource('/helloWorldModel.json')
});
  1. You've done all you need to talk to your router, call your model like so:
model.get('message').then(function(json) {
  console.log(json);
});
// Result:
{
  json: {
    message: "Hello World!"
  }
}

When To Use Falcor

**_Consider the Falcor approach when you are developing a client/server architecture that is intended to provide a rich client user experience._**
Good Fit Poor Fit
Fetching large amounts of small resources (e.g. web components, JSON, metadata, etc.) Fetching small amounts of large resources (e.g. web pages, images, files, etc.)
Aggregating heterogeneous services efficiently (e.g. microservices or loosley-coupled modules) Speaking to a single back-end data source or service provider
Delivering responsive and capable end-user client experiences Systems integration and public APIs; static websites
Heterogeneous and evolving data access patterns (multiple devices, changing use cases)

License

Apache 2.0

falcor.net's People

Contributors

craigsmitham avatar darcy-buttrose avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.