WEBAPI Integrated Swagger

Source: Internet
Author: User

1. Swagger (commonly known as: Stockings elder brother) What is the thing?

Swagger is a normative and complete framework for generating, describing, invoking, and visualizing RESTful Web services. The overall goal is to have the client and the file system update at the same speed as the server. File methods, parameters and models are tightly integrated into the server-side code, allowing the API to always stay in sync. Swagger making deployment management and using powerful APIs has never been easier.

2. What can I do with my stockings?

A. Interface, service visualization, very clear, easy to use

B. Do interface test, easy for testers to use

3.Swagger how to integrate with WEBAPI?

First step: Create a WEBAPI project

Step two: Introduce the swagger package (swashbuckle, swagger two)

Step Three: Open the solution Properties--build, tick the XML document file, save

Swagger will be saved to the bin directory under the current appdomaim after the XML comment document is generated for display on the UI

Fourth step: Find the Registration method for the Swaggerconfig file, remove this code from the comment below to load the generated XML document on the UI

The Getxmlcommentspath method is implemented as follows: Read the path to the comment file

private static string Getxmlcommentspath ()        {            return string. Format ("{0}/bin/webapiswaggerdemo.xml", System.AppDomain.CurrentDomain.BaseDirectory);        }

  

Fifth step: Open the Swggernet file and comment out the following two lines of code (it is estimated that the code in the NuGet package is not updated causing the exception to occur)

Sixth step: Swagger has been integrated successfully, in the browser input: Http://localhost:37033/swagger/ui/index can see the interface

Seventh step: Develop your own API module

<summary>/        //Update order information/        //</summary>//<param name= "input" ></param>        // /<returns></returns>        [HttpPost, Route ("Order/updateorder")] public        Outputresult UpdateOrder ( Businessmodel input)        {            return new Outputresult () {Success = false, Message = "Congratulations on your update order success!" " };        }

Specify the routing address Order/updateorder and access mode Post/get/put

Eighth Step: Test Call

Through Swaggerui you can browse and test the list of interfaces through your Comtroller module

This is too convenient for the internal use of the company, all the APIs can be used for development and testing to invoke, but it should be noted that the production environment is still to do permissions control, because the post and put method can directly manipulate the database.

The company has been using, but there is no time to summarize and share, recently written down hope to help everyone.

WEBAPI Integrated Swagger

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.