/// <summary> /// Map odata route with query string or header constraints /// </summary> public static void MapODataServiceRoute( this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model, IODataPathHandler pathHandler, IEnumerable <IODataRoutingConvention> routingConventions, object queryConstraints, object headerConstraints) { if (routes == null) { throw new ArgumentNullException("routes"); } string routeTemplate = string.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.ODataPathTemplate : (routePrefix + "/" + ODataRouteConstants.ODataPathTemplate); ODataVersionRouteConstraint routeConstraint = new ODataVersionRouteConstraint(pathHandler, model, routeName, routingConventions, queryConstraints, headerConstraints); var constraints = new HttpRouteValueDictionary(); constraints.Add(ODataRouteConstants.ConstraintName, routeConstraint); routes.MapHttpRoute( routeName, routeTemplate, defaults: null, constraints: constraints); }
public static void MapODataRoute(this HttpRouteCollection routes, string routeName, string routePrefix, IEdmModel model, IODataPathHandler pathHandler, IEnumerable <IODataRoutingConvention> routingConventions, ODataBatchHandler batchHandler) { if (routes == null) { throw Error.ArgumentNull("routes"); } if (!String.IsNullOrEmpty(routePrefix)) { int routePrefixLastCharIndex = routePrefix.Length - 1; if (routePrefix[routePrefixLastCharIndex] != '/') { // Add the last trailing slash if it doesn't have one. routePrefix += "/"; } } if (batchHandler != null) { batchHandler.ODataRouteName = routeName; routes.MapHttpBatchRoute(routeName + "Batch", routePrefix + ODataRouteConstants.Batch, batchHandler); } string routeTemplate = routePrefix + ODataRouteConstants.ODataPathTemplate; IHttpRouteConstraint routeConstraint = new ODataPathRouteConstraint(pathHandler, model, routeName, routingConventions); HttpRouteValueDictionary constraintDictionary = new HttpRouteValueDictionary() { { ODataRouteConstants.ConstraintName, routeConstraint } }; routes.MapHttpRoute(routeName, routeTemplate, defaults: null, constraints: constraintDictionary); }
public static void RegisterWebApiRoutes(System.Web.Http.HttpRouteCollection routes) { routes.MapHttpRoute( name: "ApiAction", routeTemplate: "api/{controller}/{action}", defaults: new { action = "Get" } ); }
public static void ConfigureApiGenerator(System.Web.Http.HttpRouteCollection routes, GeneratorConfig configuration) { GeneratorConfig.CheckGeneratorConfig(configuration); routes.MapHttpRoute( name: "CodeGenerator", routeTemplate: String.IsNullOrEmpty(configuration.RouteTemplate) ? "C/G/API/{action}" : configuration.RouteTemplate, defaults: null, constraints: null, handler: new GeneratorHandler(configuration) ); }
public static IHttpRoute MapHttpBatchRoute( this HttpRouteCollection routes, string routeName, string routeTemplate, HttpBatchHandler batchHandler ) { return(routes.MapHttpRoute( routeName, routeTemplate, defaults: null, constraints: null, handler: batchHandler )); }
public void MapHttpRoute1CreatesRoute() { // Arrange HttpRouteCollection routes = new HttpRouteCollection(); object defaults = new { d1 = "D1" }; // Act IHttpRoute route = routes.MapHttpRoute("name", "template", defaults); // Assert Assert.NotNull(route); Assert.Equal("template", route.RouteTemplate); Assert.Equal(1, route.Defaults.Count); Assert.Equal("D1", route.Defaults["d1"]); Assert.Same(route, routes["name"]); }
public void MapHttpRoute2WithDefaultsAndConstraintsAsDictionaryCreatesRoute() { // Arrange HttpRouteCollection routes = new HttpRouteCollection(); object defaults = new Dictionary <string, object> { { "d1", "D1" } }; object constraints = new Dictionary <string, object> { { "c1", "C1" } }; // Act IHttpRoute route = routes.MapHttpRoute("name", "template", defaults, constraints); // Assert Assert.NotNull(route); Assert.Equal("template", route.RouteTemplate); Assert.Equal(1, route.Defaults.Count); Assert.Equal("D1", route.Defaults["d1"]); Assert.Equal(1, route.Defaults.Count); Assert.Equal("C1", route.Constraints["c1"]); Assert.Same(route, routes["name"]); }