public override async Task Invoke(IOwinContext context) { var bodyStream = context.Request.Body; var sr = new StreamReader(bodyStream); var body = sr.ReadToEnd(); string queryStringPaths = null; string queryStringMethod = null; dynamic jsonGraph = null; if (string.IsNullOrEmpty(body)) { queryStringPaths = context.Request.Query["paths"]; queryStringMethod = context.Request.Query["method"]; } else { var parts = body.Split('&'); var jsonGraphEnvelopeString = parts[0].Split('=')[1]; dynamic jsonGraphEnvelope = JsonConvert.DeserializeObject(jsonGraphEnvelopeString); queryStringPaths = JsonConvert.SerializeObject(jsonGraphEnvelope.paths); queryStringMethod = parts[1].Split('=')[1]; jsonGraph = jsonGraphEnvelope.jsonGraph; } var method = queryStringMethod == "get" ? FalcorMethod.Get : queryStringMethod == "set" ? FalcorMethod.Set : FalcorMethod.Call; var paths = FalcorRouterConfiguration.PathParser.ParseMany(queryStringPaths); var request = new FalcorRequest(method, paths,jsonGraph); var response = await RouterConfiguration.Router.RouteAsync(request); var jsonResponse = FalcorRouterConfiguration.ResponseSerializer.Serialize(response); context.Response.Headers.Set("content-type", "application/json"); await context.Response.WriteAsync(jsonResponse); }
public async Task <FalcorResponse> RouteAsync(FalcorRequest request) { await Route(request).ToList().ToTask(); var response = FalcorResponse.From(_results); return(response); }
public override async Task Invoke(IOwinContext context) { var queryStringPaths = context.Request.Query["paths"]; var queryStringMethod = context.Request.Query["method"]; var method = queryStringMethod == "get" ? FalcorMethod.Get : queryStringMethod == "set" ? FalcorMethod.Set : FalcorMethod.Call; var paths = FalcorRouterConfiguration.PathParser.ParseMany(queryStringPaths); var request = new FalcorRequest(method, paths); var response = await RouterConfiguration.Router.RouteAsync(request); var jsonResponse = FalcorRouterConfiguration.ResponseSerializer.Serialize(response); context.Response.Headers.Set("content-type", "application/json"); await context.Response.WriteAsync(jsonResponse); }
public void SetSingleValue() { var router = new TestFalcorRouter(); var jsonGraphEnvelopeString = "{\"jsonGraph\":{\"todos\":{\"1\":{\"done\":false}}},\"paths\":[[\"todos\",1,\"done\"]]}"; dynamic jsonGraphEnvelope = JsonConvert.DeserializeObject(jsonGraphEnvelopeString); var paths = FalcorRouterConfiguration.PathParser.ParseMany(JsonConvert.SerializeObject(jsonGraphEnvelope.paths)); var falcorRequest = new FalcorRequest(FalcorMethod.Set, paths, jsonGraphEnvelope.jsonGraph); var falcorResponse = router.RouteAsync(falcorRequest).Result; Assert.Equal(((Dictionary<string, object>) falcorResponse.JsonGraph["todos"]) .Any(kv1 => kv1.Key.Equals("1") && ((Dictionary<string, object>) kv1.Value) .Any(kv2 => kv2.Key.Equals("done") && ((Atom)kv2.Value).Value.Equals(false))), true); }
private IObservable<PathValue> Route(FalcorRequest request) => request.Paths.ToObservable() .SelectMany(unmatched => Resolve(RootRoute, new RequestContext(request, unmatched)));
public async Task<FalcorResponse> RouteAsync(FalcorRequest request) { await Route(request).ToList().ToTask(); var response = FalcorResponse.From(_results); return response; }
public RequestContext(FalcorRequest request, FalcorPath unmatched, dynamic parameters = null) { Request = request; Unmatched = unmatched; Parameters = parameters; }
public Task<FalcorResponse> RouteAsync(FalcorRequest request) => RoutingEngine.RouteAsync(request);
public async Task<FalcorResponse> RouteAsync(FalcorRequest request) { IList<PathValue> result = await Route(request).ToList().ToTask(); var response = _responseBuilder.CreateResponse(); return response; }
private IObservable <PathValue> Route(FalcorRequest request) => request.Paths.ToObservable() .SelectMany(unmatched => Resolve(RootRoute, new RequestContext(request, unmatched)));