Esempio n. 1
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
Esempio n. 2
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            config.AddApiVersioning(cfg =>
            {
                cfg.DefaultApiVersion = new ApiVersion(1, 1);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
                cfg.ApiVersionReader  = new UrlSegmentApiVersionReader();

                /*
                 * cfg.ApiVersionReader = ApiVersionReader.Combine(
                 *  new HeaderApiVersionReader("X-Version"),
                 *  new QueryStringApiVersionReader("ver")
                 *  );
                 */

                cfg.Conventions.Controller <TalksController>()
                .HasApiVersion(1, 0)
                .HasApiVersion(1, 1)
                .Action(m => m.Get(default(string), default(int), default(bool)))
                .MapToApiVersion(2, 0);
            });

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();

            var constraintResolver = new DefaultInlineConstraintResolver()
            {
                ConstraintMap =
                {
                    ["apiVersion"] = typeof(ApiVersionRouteConstraint)
                }
            };


            // Web API routes
            config.MapHttpAttributeRoutes(constraintResolver);

            /*
             * config.Routes.MapHttpRoute(
             * name: "DefaultApi",
             * routeTemplate: "api/{controller}/{id}",
             * defaults: new { id = RouteParameter.Optional }
             * );
             */
        }
Esempio n. 3
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            // here we are configuring are results to be camel case for the purposes of making it easily worked with with JavaScript, this
            // is optional
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Web API routes
            config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 4
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            config.AddApiVersioning(cfg =>
            {
                cfg.DefaultApiVersion = new ApiVersion(1, 1);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
                cfg.ApiVersionReader  = new UrlSegmentApiVersionReader();
                //ApiVersionReader.Combine(
                //    new HeaderApiVersionReader("X-Version"),
                //    new QueryStringApiVersionReader("ver")
                //    );

                cfg.Conventions.Controller <TalksController>()  //<= This style of convension allows you to enable versioning from centralized place
                .HasApiVersion(1, 0)                            //rather than attributes
                .HasApiVersion(1, 1)
                .Action(m => m.Get(default(string), default(int), default(bool)))
                .MapToApiVersion(2, 0);
            });

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();

            var constriantResolver = new DefaultInlineConstraintResolver() // <== You have to enable this to enable Url Segmention Versioning
            {
                ConstraintMap =
                {
                    ["apiVersion"] = typeof(ApiVersionRouteConstraint)
                }
            };


            // Web API routes
            config.MapHttpAttributeRoutes(constriantResolver);

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 5
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            //Web API versioning
            config.AddApiVersioning(cfg => {
                cfg.DefaultApiVersion = new Microsoft.Web.Http.ApiVersion(1, 0);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
            });
            // Web API routes
            config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 6
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            config.AddApiVersioning(cfg =>
            {
                cfg.DefaultApiVersion = new ApiVersion(1, 1);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
                cfg.ApiVersionReader  = new UrlSegmentApiVersionReader();
                //ApiVersionReader.Combine(
                //new HeaderApiVersionReader("X-Version"),
                //new QueryStringApiVersionReader("ver"));
            });

            //Change Code to Json
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();


            var constraintResolve = new DefaultInlineConstraintResolver()
            {
                ConstraintMap =
                {
                    ["apiVersion"] = typeof(ApiVersionRouteConstraint)
                }
            };

            // Web API routes
            config.MapHttpAttributeRoutes(constraintResolve);

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 7
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            // controlling contract serialization to use camel casing when returning json data. Works better with Javascript clients
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            config.AddApiVersioning(cfg =>
            {
                cfg.DefaultApiVersion = new Microsoft.Web.Http.ApiVersion(1, 1);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
                cfg.ApiVersionReader  = ApiVersionReader.Combine(new HeaderApiVersionReader("X-Version"),
                                                                 // X-Version is the header to read from
                                                                 new QueryStringApiVersionReader("ver"));

                // we can add conventions so that we don't have to use attributes on controllers and controller actions
                // Here we're saying that the talks controller supports versions 1.1 and 1.0. In addition the get action supports version 2.0
                cfg.Conventions.Controller <TalksController>()
                .HasApiVersion(1, 0)
                .HasApiVersion(1, 1)
                .Action(m => m.Get(default(string), default(int), default(bool)))
                .MapToApiVersion(2, 0);
            });

            // can also version using Content-Type and Accept headers
            // As well we can version using version info in url see UrlSegmentApiVersionReader();
            // Web API routes
            config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 8
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            config.AddApiVersioning(cfg =>
            {
                cfg.DefaultApiVersion = new Microsoft.Web.Http.ApiVersion(1, 1);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
                cfg.ApiVersionReader  = //new UrlSegmentApiVersionReader();
                                        ApiVersionReader.Combine(
                    new HeaderApiVersionReader("X-Version"),
                    new QueryStringApiVersionReader("ver"));

                cfg.Conventions.Controller <TalksController>()
                .HasApiVersion(1, 0)
                .HasApiVersion(1, 1)
                .Action(mbox => mbox.Get(default(string), default(int), default(bool)))
                .MapToApiVersion(2, 0);
            });

            // Change Case of JSON
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();


            // Web API routes
            config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);
        }
Esempio n. 9
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            config.AddApiVersioning(cfg =>
            {
                cfg.DefaultApiVersion = new ApiVersion(1, 1);
                cfg.AssumeDefaultVersionWhenUnspecified = true;
                cfg.ReportApiVersions = true;
            });

            //camelcased serialization
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Web API routes
            config.MapHttpAttributeRoutes();

            //    config.Routes.MapHttpRoute(
            //        name: "DefaultApi",
            //        routeTemplate: "api/{controller}/{id}",
            //        defaults: new { id = RouteParameter.Optional }
            //    );
        }
Esempio n. 10
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            AutofacConfig.Register();

            // change case of json
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();

            // JSON.Net circular reference
            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
                Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling =
                Newtonsoft.Json.PreserveReferencesHandling.None;

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }