using System; using Nancy; using Nancy.Hosting.Self; using Nancy.Responses.Negotiation; using System.Collections.Generic; using Nancy.Responses; using Nancy.Bootstrapper; namespace negotiation { public class MyBootstrapper : DefaultNancyBootstrapper { protected override NancyInternalConfiguration InternalConfiguration { get { var processors = new[] { typeof(MyResponseProcessor) }; return NancyInternalConfiguration.WithOverrides(x => x.ResponseProcessors = processors); } } } class MainClass { public static void Main (string[] args) { using (var host = new NancyHost(new Uri("http://localhost:1234"))) { StaticConfiguration.DisableErrorTraces = false; host.Start(); Console.WriteLine ("Hello from nancy"); Console.ReadLine(); } } } public class MyRequestModel {} public class MyModule : NancyModule { public MyModule () { Get ["/"] = c => { return Negotiate.WithModel(new MyRequestModel()); }; } } public class MyResponseProcessor : IResponseProcessor { private MediaRange MediaType = new MediaRange("application/vnd.blah.gnn.v1"); public IEnumerable> ExtensionMappings { get { yield break;}} public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context) { var contentTypeResult = MediaType.MatchesWithParameters (requestedMediaRange) ? MatchResult.ExactMatch : MatchResult.NoMatch; return new ProcessorMatch { ModelResult = MatchResult.DontCare, RequestedContentTypeResult = contentTypeResult }; } public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context) { var myModel = new {Success = true}; return new JsonResponse (myModel, new DefaultJsonSerializer()); } } }