轻松编写 API 文档
这是我的第一篇技术博客,所以我非常兴奋。
如何轻松编写 API 文档?
我们都知道,对于我们开发人员来说,编写代码非常容易,但说到文档编写,就感觉非常枯燥乏味,不知道是不是只有我这么觉得。
我最近偶然发现了这个 NPM 包,简直惊艳不已。
API链接 - apiDOC
为什么要用这种方式进行文档记录?
这个软件包的文档非常清晰简洁,但我只想提几点我非常喜欢 apiDOC 的地方。
-
非常容易上手。
-
实现方式非常简单,代码也易于理解。看看代码片段,你就能明白如何通过添加注释来实现。这里用到了各种参数,请查阅文档了解详情。这使得 API 文档的编写变得轻松简单。
/**
* @api {get} /user/:id Request User information
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "firstname": "John",
* "lastname": "Doe"
* }
*
* @apiError UserNotFound The id of the User was not found.
*
* @apiErrorExample Error-Response:
* HTTP/1.1 404 Not Found
* {
* "error": "UserNotFound"
* }
*/
- 它能自动生成API文档,而且界面非常漂亮。您可以参考下面的演示。是不是很棒?
- 它支持多种语言,例如 Java、JavaScript、PHP、Perl、Python、Ruby、Lua 等等。
如果你觉得这篇博客对你有所帮助,请分享给你的其他开发者,帮助他们成长。祝好!
让我们保持联系,
请在 Twitter 上关注我 - Twitter
