티스토리 뷰

개발/기타

apidoc 사용법

senni 2019. 8. 22. 12:19

공식사이트: http://apidocjs.com/

 

apiDoc - Inline Documentation for RESTful web APIs

Demo This is an example documentation: watch demo output » presentation (speakerdeck.com)

 

1. npm, node.js 설치

2. apidoc 설치 ($ npm install apidoc -g)

3. apidoc command 명령어를 사용할 디렉토리에 아래 소스로 apidoc.json 파일 생성

{
  "name": "example",
  "version": "0.1.0",
  "description": "apiDoc basic example",
  "title": "Custom apiDoc browser title",
  "url" : "https://api.github.com/v1"
}

4. sample.js 소스 생성(파일명은 아무거나 사용해도 무방함)

/**
 * @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"
 *     }
 */

5-1. command에서 "apidoc"라는 명령어를 실행하면 자동으로 디렉토리 js 소스를 읽어와 컴파일하여 doc라는 폴더를 생성하여 그 안에 파일 생성

5-2. "apidoc -i src -o apidoc" 처럼 소스폴더(-i)와 타겟폴더(-o) 옵션을 지정하여 실행하는 것도 가능

6. 기타 설정  자세한 사용법은 URL 참고

7. 컴파일 된 파일은 서버 등에 올린 후 인터넷 브라우저로 index.html에 접속해 확인 가능

 

 

참고url: https://wiki.arone.co.kr/pages/viewpage.action?pageId=3080227

댓글