If you are using NancyFX, likely at some point you needed to generate a URI of another route in your application. When I first ran into this problem, I was looking for some type of built-in URI builder, similar to what you would do with ASP.NET MVC’s Url.Action().
Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
Nancy.LinkerLuckily, I found Nancy.Linker by Christian Horsdal.
Simple URI builder for named Nancy routes with optional pass through of query parameters.It’s really that simple. What it allows you to do is generate URI’s based on the names given to your routes. If you are not naming your routes yet, you will need to do so. This is fairly straightfowrad, and you really only need to do it if you need to use the linker.
UsageFirst thing we need to do is acquire the Nancy.Linker package:
PM> Install-Package Nancy.LinkerNow here is an example of an route without a defined name: To give this route a name, simply supply it as the first argument of the route builder. In order to build a URI, we must take a dependency on IResourceLinker in our Nancy Module. I was unable to have IResourceLinker automatically register with my container, so I’ve registered it in my Boostrapper. Now we we can generate a URI to a named route. In my example, I’m going to create another route that is simply going to return the URI of our existing route named “HelloWorldRoute”. Now if we access http://localhost:5000/findhelloworld via Postman, our results as expected.
One thought to “Nancy.Linker: NancyFX URI Builder”