Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Created September 22, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyond-code-github/6661649 to your computer and use it in GitHub Desktop.
Save beyond-code-github/6661649 to your computer and use it in GitHub Desktop.
Startup.cs for Owin Hello world including Json media type handler
namespace OwinModulesHelloWorld
{
using System.IO;
using Newtonsoft.Json;
using Owin;
using Superscribe.Owin;
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new SuperscribeOwinConfig();
config.MediaTypeHandlers.Add(
"text/html",
new MediaTypeHandler { Write = (res, o) => res.WriteAsync(o.ToString()) });
config.MediaTypeHandlers.Add(
"application/json",
new MediaTypeHandler
{
Write = (res, o) => res.WriteAsync(JsonConvert.SerializeObject(o)),
Read = (req, type) =>
{
object obj;
using (var reader = new StreamReader(req.Body))
{
obj = JsonConvert.DeserializeObject(reader.ReadToEnd(), type);
};
return obj;
}
});
app.UseSuperscribeModules(config);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment