Created
September 22, 2013 16:38
-
-
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
This file contains 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
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