Once you’ve written the API, you have to document the API, which is a lot of trouble if you write it all by hand, so you have to use ApidOC and you just write comments and you can generate the document very quickly.

The installation

The first step is to install the global module apidoc.

npm install apidoc -g
Copy the code

Modify interface comments

Go to the index.js file under the Routes project novel-API and change the comments to the following

@apigroup index ** * @apisuccess {Number} flag 1 Succeeded 0 Failed * @apisuccess {Array} books Returns the book content * @apisuccess {String} MSG Returns the message * * @apisuccessexample {json} Success-response: * HTTP/1.1 200 OK * {*"flag": 1,
 *      "books": [* {*"_id": "5816b415b06d1d32157790b1",
 *            "title": "The market",
 *            "author": "Chen" east",
 *            "shortIntro": "Rising in ruin, rising in desolation. The sea turned to dust, the lightning dried up, the mist drew near the earth once more, the chains of the world were opened, and a whole new world was revealed...",
 *            "cover": "http://statics.zhuishushenqi.com/agent/http%3A%2F%2Fimg.1391.com%2Fapi%2Fv1%2Fbookcenter%2Fcover%2F1%2F1228859%2F122885 9_fac7917a960547eb953edf0b740cef3a.jpg%2F",
 *            "site": "zhuishuvip",
 *            "majorCate": "Fantasy",
 *            "minorCate": "Oriental Fantasy",
 *            "allowMonthly": false,
 *            "banned": *, 0"latelyFollower": *, 283375"retentionRatio": "73.42"*} *], *"msg": "OK"*} * * * @apierrorexample Error-Response: * HTTP/1.1 404 Not Found * {"flag": 0."msg": "There is a problem with rankingId"} * /Copy the code

@api {method} path [title] @api If there is no @api apidoc will ignore this comment

@apiVersion Version Sets the version of the document block. Version version number

@apiname name Defines the name of the method document block. The name will be used for the subnavigation in the generated output. Name Indicates the name of the method

@apigroup name defines which group the method document block belongs to. The group will be used for the main route in the generated output. Name Group name. Also used as a navigation title.

@apisuccess [(group)] [{type}] field [description] Parameter is returned successfully. (group) Optional All parameters will be grouped by this name. No group, default Success 200 setting. {type} Optional Return type field Return identifier Description Description

@apiParamExample [{type}] [title] example Parameter request example. {type} Optional response format Title Short for example Example Detailed example

@apierRorexample [{type}] [title] example An example of an error return message, output as preformatted code. {type} Optional response format Title Short for example Example Detailed example

Configure NPM run doc

Open package.json file to add doc configuration

"doc": "apidoc -i routes/ -o public/"
Copy the code

Routes/The folder where you want to export the API document. Public/Output documents to public folder, no automatic creation. To see the generated API documentation, run NPM run doc to http://localhost:3000/.

The address of the document generated online

api.langpz.com/

My blog and Github, like to diandian star, thank you.

github.com/lanpangzhi

blog.langpz.com

reference

Github.com/apidoc/apid…