예제 #1
0
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                var name = context.Request.Query.Get("name");
                var x = int.Parse(context.Request.Query.Get("x"));
                var y = int.Parse(context.Request.Query.Get("y"));
                var e = Enum.Parse(typeof(MyEnum), context.Request.Query.Get("e"));

                var mc = new MyClass { Name = name, Sum = (x + y) * (int)e };

                var json = JsonConvert.SerializeObject(mc);
                var enc = System.Text.Encoding.UTF8.GetBytes(json);
                context.Response.ContentType = "application/json";

                // sync write or async write
                if (context.Request.Query.Get("sync") == "true")
                {
                    context.Response.Body.Write(enc, 0, enc.Length);
                    return EmptyTask; // Task.FromResult<object>(null)
                }
                else
                {
                    return context.Response.Body.WriteAsync(enc, 0, enc.Length);
                }
            });
        }
예제 #2
0
        public void Configuration(IAppBuilder app)
        {
            app.Run(context =>
            {
                var name = context.Request.Query.Get("name");
                var x = int.Parse(context.Request.Query.Get("x"));
                var y = int.Parse(context.Request.Query.Get("y"));

                var mc = new MyClass { Name = name, Sum = x + y };

                var json = JsonConvert.SerializeObject(mc);
                var enc = System.Text.Encoding.UTF8.GetBytes(json);
                context.Response.ContentType = "application/json";
                return context.Response.Body.WriteAsync(enc, 0, enc.Length);
            });
        }