GRAPHQL more convenient API query, operation, Swagger is a convenient open API description standard, currently we have moreRestapi but conversion to GRAPHQL is a cost, fortunately swagger-to-graphql this NPM package helps us simplify the operationBasic Project
Specific project Reference Https://github.com/rong
About SwaggerSwagger can be one of the most popular rest APIs documentation generation tools for the following reasons:
Swagger can generate an interactive API console that developers can use to quickly learn and experiment with the API.
Swagger can generate client SDK code for implementations on a variety
recognized. ② maintenance difficult, not easy to find. ③ front-end development cannot be tested. (If you want to write the shortcomings, there are 5k+ words can be written out, then omitted ha)
When I developed the backend of the second app, I wrote a simple app interface management system for the backend publishing interface, as well as the front-end staff to view. EffectPS: Advantages: ① If you have multiple front-end personnel, you can ensure that you see the same document. ② through the
Bo Master is very lazy ...Swagger Official website: Http://swagger.ioGitHub Address: Https://github.com/swagger-apiOfficial Note document: http://docs.swagger.io/swagger-core/apidocs/index.htmlSwagger-ui Address: Https://github.com/swagger-api/
, Consul registration is OK.
2, configuration swagger specific content
I put Swagger's micro-service information inside the Appsetting.json.
So the data in the Startup.cs is obtained from this side.
The Configureservices method is always filled in as follows:
The contents of "" in the inside of it can be replaced.
The Configure method fills in the following content:
At this point, the swagger configura
Registerservice
At this point, Consul registration is OK.
2, configuration swagger specific content
I put Swagger's micro-service information inside the Appsetting.json.
So the data in the Startup.cs is obtained from this side.
The Configureservices method is always filled in as follows:
The contents of "" in the inside of it can be replaced.
The Configure method fills in the following content:
At this point, the
Springfox.documentation.spi.documentationtype;import Springfox.documentation.spring.web.plugins.docket;import Springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @enableswagger2//Enable Swaggerpublic Class Swaggerconfig {@Bean public Docket Createrestapi () {/** * swagger will default to Requestmap in all controllers The Ping method generates APIs, and in fact we generally onlyYou need a standard interface (like the Controller
The swagger UI can be used to intercept the controller layer, generate the request API, and display it in the browser. We can view and debug interfaces directly from the browser.1 adding Maven Dependencies Swagger - Dependency> groupId>Io.springfoxgroupId> Artifactid>Springfox-swagger
"]. Value; the stringKey = val. Substring (Val. LastIndexOf ('.') +1). Replace ("Controller",""); theXmlNode node =item. FirstChild; - if(!DiC. ContainsKey (key)) - { the DiC. TryAdd (Key, node. Innertext.trim ()); the } the } the returndic; - } the the } the}View CodeStep three: Output XML fileRight-click the item's properties, generate, tickFourth step: Show controller NotesBuild a JS file your
Swagger generates API documentation, swaggerapi documentation
1. Open the package management console and enter:
Install-Package Swashbuckle
2. Open the SwaggerConfig. cs file in the App_Start folder and find
C. IncludeXmlComments
Replace
C. IncludeXmlComments (GetXmlCommentsPath (thisAssembly. GetName (). Name ));
3. Add Method
Protected static string GetXmlCommentsPath (string name) {return string.
The commonly used annotations are:
Api
Apimodel
Apimodelproperty
Apioperation
Apiparam
Apiresponse
Apiresponses
Responseheader
1. API tagsThe API is used on classes to illustrate the role of the class. You can tag a controller class as a Swagger document resource, using the fol
= Mediatype.application_json_utf8_value, consumes = mediatype.application_json_value) @RequestBody The parameter submitted by the Messageparam Param is a JSON of this object, It will then automatically resolve to the corresponding field, or it can receive the current request data in the form of a stream, but this and the above receive method can only use one (the stream will be closed after @requestbody)Headertrue ) }) = Request.getheader ("id"); if (Stringutils.isnumeric (idstr))
.release.jar:4.3.8.release]At Org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray (Constructorresolver.java : 741) ~[spring-beans-4.3.8.release.jar:4.3.8.release]... Common frames omittedcaused By:org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type ' java.util.List At Org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound ( defaultlistablebeanfactory.java:1486) ~[spring-beans-4.3.8.release
Automated test = unittest and requests interface test cases, test express query api (2), unittestrequests
Generate a test report based on the original one:
First, generate a report file using unittest of HTMLTestRunner. py.
Then slightly modify the code:
Import requestsimpor
Previously useful in the project to Webapi external interface, found in the project has based on WEBAPI methods and comments automatically generated help documents, can also test Webapi method, the function is very powerful, now take out to share with you.First look at the generated WEBAPI document.1, the display is the first page of the build Help document, where values is controller,api The following list
When participating in a Web API project, it was found that the help page was particularly useful, and it was not only possible to automatically generate a helper document based on Webapi's methods and comments, but also to test the Webapi method on this page. I also intend to use this help page when creating a new project. In practice, discovering a new Web API p
1. Referencing the web API Test Client through NuGetReferences to play the DLL generate the following files:This is our help. Document interface2. In the project properties, make the following settings, tick the XML document file, and set the path3. Create xmldocument.xml under the App_Data folder of the project4. Open the \areas\helppage\app_start\helppageconfig.cs file and uncomment the following codeExce
Apizza (Http://apizza.cc?f=51cto) platform is divided into development mode and browse template, development mode only the user can open, browse mode is for other people to view, test use. 650) this.width=650; "src=" Http://ocrlqrwod.bkt.clouddn.com/195239_mw7H_2405364.png "style=" width:800px;height : 400px; "alt=" 195239_mw7h_2405364.png "/>The Platform supports standard HTTP protocol requests, supports adding headers, supports standard Json,xml,htm
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.