Skip to content

Instantly share code, notes, and snippets.

@ksysiekj
Created February 24, 2017 00:29
Show Gist options
  • Save ksysiekj/7863630118a6e29b5ccd861596af9634 to your computer and use it in GitHub Desktop.
Save ksysiekj/7863630118a6e29b5ccd861596af9634 to your computer and use it in GitHub Desktop.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.ConfigureJSONFormatter();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
private static void ConfigureJSONFormatter(this HttpConfiguration config)
{
// remove Json.NET
// config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
// {
// ContractResolver = new CamelCasePropertyNamesContractResolver(),
// NullValueHandling = NullValueHandling.Ignore,
// DateFormatHandling = DateFormatHandling.IsoDateFormat
// };
// use Jil
config.Formatters.RemoveAt(0);
config.Formatters.Insert(0, new JilMediaTypeFormatter());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment