Created
August 16, 2017 04:02
-
-
Save Teddybiers/5ba2010ff91878ee381e167c98b72fcc to your computer and use it in GitHub Desktop.
Default API Configure
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
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