Last active
August 29, 2015 14:20
-
-
Save walkingriver/f9260b04a3b5029f9915 to your computer and use it in GitHub Desktop.
My Default Startup Class for OWIN WebAPI apps.
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
/// <summary> | |
/// Default Startup Class for OWIN WebAPI apps | |
/// </summary> | |
/// <remarks> | |
/// Requires the following NuGet Packages to be installed: | |
/// - Install-Package Microsoft.AspNet.WebApi.Owin | |
/// - Install-Package Microsoft.AspNet.WebApi.WebHost (If IIS-hosted) | |
/// </remarks> | |
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var config = new HttpConfiguration(); | |
ConfigureRoutes(config); | |
ConfigureJson(config); | |
app.UseWebApi(config); | |
} | |
private static void ConfigureRoutes(HttpConfiguration config) | |
{ | |
// I only want Attribute Routing | |
config.MapHttpAttributeRoutes(); | |
// For now, let's turn on all error details. | |
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; | |
} | |
private static void ConfigureJson(HttpConfiguration config) | |
{ | |
var formatters = config.Formatters; | |
var jsonFormatter = formatters.JsonFormatter; | |
// This lets us get JSON as the default in the browser | |
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); | |
// This camelCases our JSON | |
var settings = jsonFormatter.SerializerSettings; | |
settings.Formatting = Formatting.Indented; | |
settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment