Skip to content

pvasek/falcor-net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

falcor-net

This is Falcor router implementation for .NET framework.

Installation

Install-Package Falcor.Router.Owin

Demo

You can see our Falcor.WebExample in action here.

Example

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseFalcor(GetFalcorRoutes());
    }
    
    private List<Route> GetFalcorRoutes() 
    {
        var routes = new List<Route>();
        
        routes.MapRoute(
            Keys.For("Events"),
            Integers.Any(),
            async (ctx, events, keys) => 
                {
                	// your retrieval logic
                	var eventList = await db.Events
                        .Select(i => i.Id)
                        .Take(model.Events.Count)
                        .ToListAsync();
                		
                	// transform it into falcor PathValue result
                    var result = eventList
                        .Select((i, index) => new PathValue(
                            new Ref(Keys.For("EventById"), Keys.For(i)),
                        	Keys.For("Events"), 
                        	Integers.For(index))
                        );
        
                    return result;
                });
        
        routes.MapRoute(
            Keys.For("EventById"),
            Keys.Any(),
            Keys.For("Name", "Number", "Country"),
            async (ctx, eventById, keys, properties) => 
                {
                    var result = new List<PathValue>();
                    var items = await db.Events.FindAsync(keys.Values);
                        
                    foreach (var item in items)
                    {
                		var key = item.Id;
                        if (properties.Values.Contains("Name"))
                        {
                            result.Add(new PathValue(item.Name, eventById, Keys.For(key), new Keys("Name")));
                        }
                        if (properties.Values.Contains("Number"))
                        {
                            result.Add(new PathValue(item.Number, eventById, Keys.For(key), new Keys("Number")));
                        }
                        if (properties.Values.Contains("Country"))
                        {
                            var reference = new Ref(new Keys("CountryById"), new Keys(item.Country.Id));
                            result.Add(new PathValue(reference, eventById, Keys.For(key), new Keys("Country")));
                        }
                    }
        
                    return result.AsEnumerable();
                }
            );
    }
}

You can see more in our Falcor.WebExample project

Missing pieces

  • set/call are not implemented at all
  • router doesn't collapse paths - PathCollapser needs to be implemented
  • during route processing the same reference can be resolved multiple times
  • parser/router dosen't support mixing ranges with properties [0..10,'length']

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages