Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to list all available routes in a Nancy application?

Tags:

nancy

I'm implementing an API via a web service, using Nancy.

I'd like to have a /help or /docs page that programmatically lists all of the available routes, so that I can provide API users with automatically generated/updated documentation.

Any ideas on how to accomplish this? (Inside a route handler, "this.routes" gives access to a collection of defined routes - but only on the current NancyModule. I'd need a programmatic way to list all registered routes, not just ones in the current module)

like image 687
John Rose Avatar asked Mar 25 '13 20:03

John Rose


2 Answers

Not exactly what you need, but there is also a built in dashboard panel in Nancy. To enable it do:

public class CustomBootstrapper : DefaultNancyBootstrapper
{
    protected override DiagnosticsConfiguration DiagnosticsConfiguration
    {
        get { return new DiagnosticsConfiguration { Password = @"secret"}; }
    }
}

And then you can access it on {yournancyapp}/_nancy

https://github.com/NancyFx/Nancy/wiki/Diagnostics

like image 182
Alex Lapa Avatar answered Nov 16 '22 21:11

Alex Lapa


You can do it by taking a dependency on the IRouteCacheProvider and calling GetCache - we actually do this in one of our demos in the main repo:

https://github.com/NancyFx/Nancy/blob/master/src/Nancy.Demo.Hosting.Aspnet/MainModule.cs#L13

like image 34
Steven Robbins Avatar answered Nov 16 '22 22:11

Steven Robbins