Last active
November 25, 2015 16:53
-
-
Save DalSoft/6958b55f803ef6e43ff0 to your computer and use it in GitHub Desktop.
Professional WebApi Part 1 - WebApi bootstrap without any bloat using Owin
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
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var config = new HttpConfiguration(); | |
var jsonSerializerSettings = config.Formatters.JsonFormatter.SerializerSettings; | |
//Remove unix epoch date handling, in favor of ISO | |
jsonSerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff" }); | |
//Remove nulls from payload and save bytes | |
jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore; | |
// Make json output camelCase | |
jsonSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | |
// Remove xml this will make json the default and your life easier (unless you really need to support xml) | |
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "text/xml")); | |
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml")); | |
// Attribute routing | |
config.MapHttpAttributeRoutes(); | |
// WebApi | |
app.UseWebApi(config); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment