Skip to content

Instantly share code, notes, and snippets.

@Teddybiers
Created August 16, 2017 04:02
Show Gist options
  • Save Teddybiers/5ba2010ff91878ee381e167c98b72fcc to your computer and use it in GitHub Desktop.
Save Teddybiers/5ba2010ff91878ee381e167c98b72fcc to your computer and use it in GitHub Desktop.
Default API Configure
using Microsoft.Web.Http.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Web.Http;
using System.Web.Http.Routing;
namespace USparkApi
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
GlobalConfiguration.Configuration.MessageHandlers.Add(new HttpHeaderHandler());
// Use with Microsoft.AspNet.WebApi.Versioning NuGet Package
var constraintResolver = new DefaultInlineConstraintResolver()
{
ConstraintMap =
{
["apiVersion"] = typeof( ApiVersionRouteConstraint )
}
};
config.MapHttpAttributeRoutes(constraintResolver);
config.AddApiVersioning();
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment