[nodejs] iodocs를 이용한 rest api 정의.
[nodejs] iodocs를 이용한 rest api 정의.
이번에 소개해 드릴 시스템은 iodocs 입니다.
요즘 부쩍 app <-> server 와 통신하는 restful api 설계할 일이 많아져서 쉽게 설계 및
요청에 대한 테스트가 가능하도록 지원하는 도구를 찾던중 swagger와 nodejs 의
iodocs 라는것을 찾았습니다.
저는 nodejs를 사랑하기 때문에 iodocs를 설치 해 보도록 하겠습니다.
일단 nodejs 설치 및 redis 설치가 필요합니다.
설치는 간단하게.
RedHat 계열 : yum install nodejs redis
MAC OSX 계열 : brew install nodejs redis
Ubuntu : apt-get install nodejs redis
step1. iodocs 설치
아래와 같이 dependency 설치 및 iodocs 설치합니다.
$ git clone http://github.com/mashery/iodocs.git
$ cd iodocs
$ npm install -d
step 2. 실행
config.json파일에서 환경 설정 후 실행
$ mv config.json.sample config.json
$ node app.js
웹 메인화면에 샘플 api가 등록 되어 있습니다.
USA Today 를 확인 해 보았습니다.
오 !! 놀랍습니다.
step 3. Custum API 추가
iodocs/public/data/rocksea.json
{
"endpoints": [
{
"name": "Resource Group A",
"methods": [
{
"MethodName": "Method A1 User",
"Synopsis": "Grabs information from the A1 data set for a specific user",
"HTTPMethod": "GET",
"URI": "/user/:userid/:pwd",
"RequiresOAuth": "N",
"parameters": [
{
"Name": "userid",
"Required": "Y",
"Default": "",
"Type": "string",
"Description": "Description of the first parameter."
},
{
"Name": "pwd",
"Required": "Y",
"Default": "",
"Type": "string",
"Description": "The password parameter that is in the URI."
}
]
}
]
}
]
}
실행
확인.
Response가 정확히 오는지 확인 합니다.
rest api에 대한 client & server 간 protocol 정의시 적합한 오픈소스가 아닐까 생각합니다.
참조 : https://github.com/mashery/iodocs
Swagger도 경험 해 보시고 싶으시다면
.by rocksea