Using URI Templates aka RFC 6570 for routing in Nancy
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.paket
Example
assets
src/Nancy.Routing.UriTemplates
tests
.gitattributes
.gitignore
Nancy.Routing.UriTemplates.sln
Nancy.Routing.UriTemplates.sln.DotSettings
README.md
appveyor.yml
paket.dependencies
paket.lock

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