Created
January 13, 2014 14:56
-
-
Save neuecc/8401722 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
static Task emptyTask = Task.FromResult<object>(null); | |
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; | |
} | |
else | |
{ | |
return context.Response.Body.WriteAsync(enc, 0, enc.Length); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment