Last active
August 29, 2015 14:06
-
-
Save davidwhitney/840364fa11de2d44fc9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseModule : NancyModule | |
{ | |
protected readonly int Version; | |
protected BaseModule(string moduleName, int? version) | |
: base((version == null ? "/" : "/v" + version) + "/" + moduleName) | |
{ | |
Version = !version.HasValue ? 1 : version.Value; | |
} | |
} | |
public class PointlessModuleVersionLess : PointlessModule { public PointlessModuleVersionLess() : base(null) { } } | |
public class PointlessModule : BaseModule | |
{ | |
public PointlessModule() : this(1) | |
{ | |
} | |
public PointlessModule(int? ver) | |
: base("/Pointless/", ver) | |
{ | |
MapMethods(); | |
} | |
private void MapMethods() | |
{ | |
Get["/"] = parameters => | |
{ | |
return | |
Negotiate.WithModel(new {success = true}) | |
.WithStatusCode(HttpStatusCode.OK) | |
.WithHeader("X-Api-Version", Version.ToString()); | |
}; | |
} | |
} | |
public class PointlessModuleV2 : BaseModule | |
{ | |
public PointlessModuleV2() | |
: base("/Pointless/", 2) | |
{ | |
Get["/"] = parameters => | |
{ | |
return | |
Negotiate.WithModel(new { success = true }) | |
.WithStatusCode(HttpStatusCode.OK) | |
.WithHeader("X-Api-Version", Version.ToString()); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment