Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created January 13, 2014 14:56
Show Gist options
  • Save neuecc/8401722 to your computer and use it in GitHub Desktop.
Save neuecc/8401722 to your computer and use it in GitHub Desktop.
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