Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

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

README.md

trail icon

Nancy.Routing.UriTemplates Build status NuGet version codecov.io codefactor

Using URI Templates aka RFC 6570 for routing in Nancy.

Introduction

You can use URI Templates to define routes in Nancy.

public class PeopleModule : Nancy.Routing.UriTemplates.UriTemplateModule
{
    public PeopleModule()
    {
        // by default you'll be creating typical routes
        Get("person/{id}", p => GetModel(p.id));
            
        // and URI Templates are opt-in
        using(Templates)
        {
            Get("people{;include}{/page}{?name}", p => GetPeople(p.include, p.page, p.name));
        }
    }
}

The second route will for example match a request to people;include=hobbies,friends/4?name=Tomasz

As you can see, URI Templates give more expressive syntax:

  • variables can be extracted not only from segments but also other URI parts including query strings ({?name}) and path parameters ({;include})
  • all variables can have multiple values

Finally, URI Templates can also be used outside routing to mint identifiers. For example to used them as links in a REST API.

More

See some discussion here: http://t-code.pl/blog/2016/11/Towards-server-side-routing-with-URI-Templates/

The icon desiged by Gabriele Debolini from The Noun Project

You can’t perform that action at this time.