Skip to content

Instantly share code, notes, and snippets.

@DalSoft
Last active November 25, 2015 16:53
Show Gist options
  • Save DalSoft/6958b55f803ef6e43ff0 to your computer and use it in GitHub Desktop.
Save DalSoft/6958b55f803ef6e43ff0 to your computer and use it in GitHub Desktop.
Professional WebApi Part 1 - WebApi bootstrap without any bloat using Owin
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