public async Task Invoke(HttpContext context, IDictionary<string, string> parameters) { var types = parameters.ParseEnumerable("types").ToArray(); if (types.Length == 0) { await context.RespondWith( new MissingParameterProblem("types") .EnableCaching()); return; } var list = await _store.RetrieveByType(types); await context.RespondWith(new RawJson(list.ToJsonArray())); }
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters) { if (context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase)) { // CORS - this is super basic... var headers = context.Response.Headers; headers["Access-Control-Allow-Origin"] = "*"; headers["Access-Control-Allow-Methods"] = "POST"; headers["Access-Control-Allow-Headers"] = context.Request.Headers["Access-Control-Request-Headers"]; context.Response.StatusCode = 200; await context.Response.WriteAsync(""); return; } IEnumerable<Message> messages = null; if (context.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase)) { try { messages = ReadMessage(context.Request).ToArray(); foreach (var message in messages) { _messageServerBus.SendMessage(message); } } catch (JsonReaderException exception) { await context.RespondWith(new InvalidJsonProblem(exception).EnableCors()); return; } catch (Exception exception) { await context.RespondWith(new ExceptionProblem(exception).EnableCors()); return; } await context.RespondWith( new HttpStatusResponse(HttpStatusCode.Accepted, "Accepted: " + string.Join(", ", messages.Select(m => m.Id.ToString("N")))) .EnableCors()); } else { await context.RespondWith( new InvalidMethodProblem(context.Request.Method, "POST") .EnableCors()); } }
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters) { var filters = GetFilters(parameters); IEnumerable<string> list; var types = parameters.ParseEnumerable("types").ToArray(); if (types.Length > 0) { list = await _requests.Query(filters, types); } else { list = await _requests.Query(filters); } await context.RespondWith( new RawJson(list.ToJsonArray())); }
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters) { var resourceOptions = _resourceOptionsProvider.BuildInstance(); var json = $@"{{ ""resources"": {{ ""browserAgentScriptTemplate"" : ""{resourceOptions.BrowserAgentScriptTemplate}"", ""hudScriptTemplate"" : ""{resourceOptions.HudScriptTemplate}"", ""messageIngressTemplate"" : ""{resourceOptions.MessageIngressTemplate}"", ""metadataTemplate"" : ""{resourceOptions.MetadataTemplate}"", ""contextTemplate"" : ""{resourceOptions.ContextTemplate}"", ""clientScriptTemplate"" : ""{resourceOptions.ClientScriptTemplate}"" }} }}"; await context.RespondWith( new RawJson(json) .AsFile("glimpse.json")); }
public async Task Invoke(HttpContext context, IDictionary<string, string> parameters) { var metadata = GetMetadata(); await context.RespondWith(new Json(metadata)); }