public NancyDemoModule(IResourceLinker linker) { Get["HelloWorldRoute", "/nancy/demo/{MyQueryParameter:string}"] = parameters => new[] {"Hello", "World", (string) parameters.MyQueryParameter}; Get["FindHelloWorld", "/nancy/findhelloworld"] = parameters => new[] { linker.BuildAbsoluteUri(Context, "HelloWorldRoute", new {MyQueryParameter = "CodeOpinion"}) }; Get["GzipTest", "/nancy/gziptest"] = parameters => { return new Response { ContentType = "application/json", StatusCode = HttpStatusCode.OK, Contents = stream => { var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AspNet5Nancy.fakedata.json"); using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) { var content = Encoding.UTF8.GetBytes(reader.ReadToEnd()); stream.Write(content, 0, content.Length); } } }; }; }
public NancyDemoModule(IResourceLinker linker) { Get["HelloWorldRoute", "/nancy/demo/{MyQueryParameter:string}"] = parameters => new[] { "Hello", "World", (string)parameters.MyQueryParameter }; Get["FindHelloWorld", "/nancy/findhelloworld"] = parameters => new[] { linker.BuildAbsoluteUri(Context, "HelloWorldRoute", new { MyQueryParameter = "CodeOpinion" }) }; Get["GzipTest", "/nancy/gziptest"] = parameters => { return(new Response { ContentType = "application/json", StatusCode = HttpStatusCode.OK, Contents = stream => { var resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("AspNet5Nancy.fakedata.json"); using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) { var content = Encoding.UTF8.GetBytes(reader.ReadToEnd()); stream.Write(content, 0, content.Length); } } }); }; }
public IndexModule(IResourceLinker linker) { Get["home", "/"] = parameters => Response.AsJson(new { serverTime = DateTime.UtcNow.ToString(@"yyyy-MM-ddTHH\:mm\:ss"), apiName = "xxxx", version = "v0.2", hone = linker.BuildAbsoluteUri(Context, "home") }); }
public StatisticsModule(IProjectionStats stats, IResourceLinker resourceLinker) { Get("/", args => { var results = stats.OrderBy(p => p.ProjectorId).Select(p => new ProjectorSummary { ProjectorId = p.ProjectorId, LastCheckpoint = p.LastCheckpoint.Checkpoint, LastCheckpointUpdatedUtc = p.LastCheckpoint.TimestampUtc, Url = Context.Request.Url + $"/{p.ProjectorId}" }); return(results); }, null, "GetAll"); Get("/{id}", args => { string id = args.Id; return(new { ProjectorId = id, LastCheckpoint = stats.Get(id).LastCheckpoint.Checkpoint, LastCheckpointUpdatedUtc = stats.Get(id).LastCheckpoint.TimestampUtc, Properties = stats.Get(id).GetProperties().Select(p => new ProjectorProperty { Key = p.Key, Value = p.Value.Value, LastUpdatedUtc = p.Value.TimestampUtc }), EventsUrl = resourceLinker.BuildAbsoluteUri(Context, "GetEvents", new { args.id }).ToString() }); }, null, "GetSpecific"); Get("/{id}/events", args => { string id = args.Id; return(new ProjectorEventCollection { ProjectorId = id, Events = stats.Get(id).GetEvents().Select(@event => new ProjectorEvent { Body = @event.Body, TimestampUtc = @event.TimestampUtc }) }); }, null, "GetEvents"); Get("/{id}/eta/{targetCheckpoint}", args => { string id = args.Id; TimeSpan?eta = stats.GetTimeToReach(id, args.targetCheckpoint); return(new { Eta = eta }); }, null, "GetEta"); }
public string BuildAbsoluteRoute(Route route, dynamic parameters = null) { return(_linker.BuildAbsoluteUri(_context, route.Name, parameters).ToString()); }