Getting Started with Falcor.NET - falcordotnet/falcor.net GitHub Wiki

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
    
  2. 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("hello"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.

  3. In your OWIN startup class, configure your Falcor.NET router endpoint:

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseFalcor("/helloWolrdModel.json", routerFactory: config => new HelloWorldRouter());
            ...
        }
    }
    
    
  4. 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')
    });
    
  5. 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!" } }