Very useful API Management--sawgger

Source: Internet
Author: User

1. Open the NuGet package

2. Install the following two packages

3. After the installation, the SwaggerConfig.cs class will appear, and the contents of the content can be modified.

Code:

[Assembly:preapplicationstartmethod (typeof (Swaggerconfig), "Register")]namespace webapplication1{public    Class Swaggerconfig    {public        static void Register ()        {            var thisassembly = typeof (Swaggerconfig). Assembly;            Globalconfiguration.configuration                . Enableswagger (c + =                {                    c.singleapiversion ("v1", "WebApp");                })                . Enableswaggerui (c + =                {                    getxmlcommentspath ();                });        }        private static string Getxmlcommentspath ()        {            return [email protected] ' { System.appdomain.currentdomain.basedirectory}\bin\webapi.xml ";        }}

4. Add WebApi.cs Class

Code:

namespace webapi{public    static class Webapiconfig    {public        static void Register (Httpconfiguration config)        {            //Web API Configuration and Services            //Web API Routes            CONFIG. Maphttpattributeroutes ();            Config. Routes.maphttproute (                name: "DefaultApi1",                routetemplate: "Api/{controller}/{action}/{id}",                defaults : new {id = routeparameter.optional}            );            Config. Routes.maphttproute (               name: "DefaultApi2",               routetemplate: "Api/{controller}/{action}/{id}",               defaults:new {action= "get", id = routeparameter.optional}           );}}}    

5. Modify the Global.asax class

Code:

public class MvcApplication:System.Web.HttpApplication    {        protected void Application_Start ()        {            Arearegistration.registerallareas ();            Routeconfig.registerroutes (routetable.routes);            Globalconfiguration.configure (webapiconfig.register);   This is to be added        }    }

6. Set the class to be debugged

7. Set up the generated XML document

8. Run the project and open the browser input http://localhost:23092/swagger/

Results show:

Very useful API Management--sawgger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.