Skip to content

pvasek/falcor-net

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

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