Node Express REST API Document while coding

I have used apidoc in my  Node Express REST Project . It works like charm and cpable to handle document versioning.

APIDOC

Inline Documentation for RESTful web APIs

http://apidocjs.com/#param-api-description


1.npm install apidoc - g

2.

/**
 * @api {get} /tasks/:id Find a task
 * @apiGroup Tasks
 * @apiDescription  User login + register user if user login for the frist time.
 * @apiParam {id} id Task id
 * @apiSuccess {Number} id Task id
 * @apiSuccess {String} title Task title
 * @apiSuccess {Boolean} done Task is done?
 * @apiSuccess {Date} updated_at Update's date
 * @apiSuccess {Date} created_at Register's date
 * @apiSuccessExample {json} Success
 *    HTTP/1.1 200 OK
 *    {
 *      "id": 1,
 *      "title": "Study",
 *      "done": false
 *      "updated_at": "2016-02-10T15:46:51.778Z",
 *      "created_at": "2016-02-10T15:46:51.778Z"
 *    }
 * @apiErrorExample {json} Task not found
 *    HTTP/1.1 404 Not Found
 * @apiErrorExample {json} Find error
 *    HTTP/1.1 500 Internal Server Error
 */

3.
apidoc - e "(node_modules|public)" - o public / apidoc.    // this will create a doc folder contain all

4. Index.js file changes
const path = require('path');

//staitc folder for docs
app.use('/public', express.static(path.join(__dirname + '/../doc')));

5. Check your site with http://localhost/public

Ref : https://blog.jscrambler.com/documenting-apis-using-apidoc-js/


Comments

Popular posts from this blog

ENOENT: no such file or directory, rename : node_modules/async

react-quill Integrate quill-image-resize-module