Swagger UI Tutorial API documentation artifact paired with node

Source: Internet
Author: User

The ASP. NET Web API uses swagger to generate online help test documents

Swagger generating the ASP. NET Web API

Objective
    • Swagger UI is an API for online document generation and testing, and is now found to be the best.
    • Why is it useful? Demo Portal
      • Support API to automatically generate synchronized online documents
        • These documents are available for project internal API audits
        • Easy for testers to understand the API
      • These documents can be published as part of the customer's product documentation
        • Support API Specification generation code, generate client and server-side skeleton code to accelerate development and test speed

Summed up a sentence is easy to use, forcing lattice high. Below I'll summarize how to quickly build a document tool locally based on the node and Swagger UI API.

Environment construction
    • Download the swagger UI (you can also download the zip file directly)
clone https://github.com/swagger-api/swagger-ui.git
    • Install Express
    • Create an empty folder Node_app
mkdir node_app
    • Initialize node, create Package.json file ()
?  ~ ? >cd node_ap?  ~/node_app ? >npm init// 下面的看你心情填写name: (node_app) node_appversion: (1.0.0)description:entry point: (index.js)test command:git repository:keywords:author:license: (ISC)
    • Install Express
express --save
    • Create Index.js
?  ~/node_app git:(master) ? >vim index.js
    • Paste the code below as Index.js
var express = require(‘express‘);var app = express();app.get(‘/‘, function (req, res) { res.send(‘Hello World!‘);});app.listen(3000, function () { console.log(‘Example app listening on port 3000!‘);});
    • Create an empty directory public in Node_app
git: (Master)?  >mkdir public? ~/node_app git: (Master)? >CD public      
    • modifying routes
      ?  ~/node_app/public git:(master) ? >vim ../index.js//在文件第三行插入下面这句话app.use(‘/static‘, express.static(‘public‘));
    • Copy all files from the Dist directory in the downloaded Swagger UI file to the public folder.

      Directory structure
    • Open node
      ?  ~/node_app git:(master) ? >node index.js
    • Open Browser, enter http://localhost:3000/static/index.html

So far, you've already configured the official demo locally. Of course, you can do it. This is built on the server.

Writing Documents and publishing
    • Writing API documentation using Swagger Editor
      • Swagger Editor is a YAML-based syntax, but don't be afraid to watch the official demo for 10 minutes.
    • Exporting Test.json Documents

      How to Export
    • Put the Test.json in the Node_app/public directory.
    • Use url = "http://petstore.swagger.io/v2/swagger.json"; the editor to modify theurl = "/static/test.json";
    • Restart the node service, open in http://localhost:3000/static/index.html the browser is your own written API document

Self-written API interface
Put request
GET request
POST Request
DELETE Request

Swagger UI Tutorial API documentation artifact paired with node

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.