Question

I am quite new to NancyFX and investigating its capabilities. Once thing I am trying to figure out is whether it's possible to compose a large site using multiple modules (classes derived from NancyModule) in a way that makes it possible to build routes from several module definitions.

For example, I have the following module, AbcModule:

public class AbcModule : NancyModule
{
    public AbcModule() : base("/api/systems/abc")
    {
        Get["/"] = _ => "ABC API Host";

        Get["/domains/"] = _ => Response.AsJson(Domains.All);
        Get["/domains/{name}"] = x => Response.AsJson(Domains.All.Single(y => x.Name == y.Name));
    }
}

What I don't want is to expose "api/systems/abc". I want this path to be defined in another module (i.e. RootModule) that defines "api/systems" and build a list of available systems at runtime. Then AbcModule is unaware of its container defines all its routes relative to some URL.

Is this possible in NancyFX?

UPDATE. Let me give you an example (and I am open to admit that I've misunderstood something, in this case please hint me where is the flaw). There is a Web service that is going to expose a potentially large collection of services or plugins. Each plugin is responsible for its own resource types and resource structure, but why should it know how its container's routing rules? Imagine that a developer is working with the plugin "music" wrapped in a Nancy MusicModule which defines routes "/rock", "/metal" and "disco". But on a production machine his code is deployed in a Web site where MusicModule becomes a part of a "Hobby" service that defines "music", "sports" and "films" routes. Finally, there is a root module that defines "api" route.

So here is the question: can MusicModule only deals with the routes that belong to its domain, with the rest of the full path be added by other modules, so on a development machine with only MusicModule available "rock" resource can be accessed directly at localhost:xxx/rock, and on a production machine it's exposed from other (chained) modules, so the access path is machinename:xxx/api/hobby/music/rock?

And if this is a bad idea, please elaborate why. What can be wrong with hiding from a module the full route path?

Was it helpful?

Solution

what you are asking for is running at a different root url, where /api/systems/ is not part of your application, but your hosting environment. Nancy does not understand the concept of global root path. It can be done quite easily by intercepting the incoming requests (using a Before hook on the application level) and re-writing the URL of the incoming URL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top