An example of using IRouteCacheProvider
, e.g. @grumpydev mentioned in this answer :
// within your module public class IndexModule : NancyModule { // add dependency to IRouteCacheProvider public IndexModule(Nancy.Routing.IRouteCacheProvider rc) { routeCache = rc; Get["/"] = GetIndex; } private Nancy.Routing.IRouteCacheProvider routeCache; private dynamic GetIndex(dynamic arg) { var response = new IndexModel(); // get the cached routes var cache = routeCache.GetCache(); response.Routes = cache.Values.SelectMany(t => t.Select(t1 => t1.Item2)); return response; } } public class IndexModel { public IEnumerable<Nancy.Routing.RouteDescription> Routes { get; set; } }
You can get routing information, such as Path
and Method
, from the Nancy.Routing.RouteDescription
list. For example, with this view:
<!DOCTYPE html> <html> <body> <p>Available routes:</p> <table> <thead><tr><th>URL</th><th>Method</th></tr></thead> <tbody> @Each.Routes <tr><td>@Current.Path</td><td>@Current.Method</td></tr> @EndEach </tbody> </table> </body> </html>
source share