apiで掲示板を作るまで

c# イシュー * 簡単なAPIを作る

BlueMixを使う

magnet88jp.hateblo.jp

nodeの管理用 yarn

nodebrew

nodeが古い

$ nodebrew ls
v6.9.1
v7.0.0

current: v6.9.1
$ 

最新版(v6.11.3)を探す

$ nodebrew ls-remote
...
v6.0.0    v6.1.0    v6.2.0    v6.2.1    v6.2.2    v6.3.0    v6.3.1    v6.4.0
v6.5.0    v6.6.0    v6.7.0    v6.8.0    v6.8.1    v6.9.0    v6.9.1    v6.9.2
v6.9.3    v6.9.4    v6.9.5    v6.10.0   v6.10.1   v6.10.2   v6.10.3   v6.11.0
v6.11.1   v6.11.2   v6.11.3   
...

最新版(v6.11.3)をインストール

$ nodebrew install-binary v6.11.3 
$ nodebrew ls
v6.9.1
v6.11.3
v7.0.0

current: v6.9.1
$ 

最新版(v6.11.3)に切り替え

$nodebrew use v6.11.3

apic edit で謎のエラー

{ Error: Cannot find module './build/Release/DTraceProviderBindings'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/magnet/.nodebrew/node/v6.11.3/lib/node_modules/apiconnect/node_modules/dtrace-provider/dtrace-provider.js:18:23)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3) code: 'MODULE_NOT_FOUND' }
MagsBook:~ magnet$ npm ls -g |grep bunyan
npm ERR! missing: extend@3.0.0, required by superagent@1.8.5
npm ERR! missing: qs@^6.2.1, required by strong-remoting@2.32.3
npm ERR! missing: options@latest, required by sse@0.0.6
npm ERR! missing: generator-swiftserver@prerelease, required by apiconnect-cli-swiftserver@1.0.8
│ │ ├─┬ bunyan@1.8.12
│ │ │ │ ├── bunyan@1.8.12 deduped
│ │ │ │ ├── bunyan@1.8.12 deduped
MagsBook:~ magnet$ 

bunyan

MagsBook:~ magnet$ npm ls -g |grep dtrace
npm ERR! missing: extend@3.0.0, required by superagent@1.8.5
npm ERR! missing: qs@^6.2.1, required by strong-remoting@2.32.3
npm ERR! missing: options@latest, required by sse@0.0.6
npm ERR! missing: generator-swiftserver@prerelease, required by apiconnect-cli-swiftserver@1.0.8
│ │ │ ├─┬ dtrace-provider@0.8.5
│ │ │ │ ├─┬ dtrace-provider@0.7.1
MagsBook:~ magnet$ 

33 dtrace-providerの最新は、0.8.5(2017/10/21時点)

解消しないので、無視

ssl 証明書

qiita

ApiDesigner でエラー

  • explorer のサンプルを実行するとエラー
curl --request POST \
  --url https://localhost:4002/api/Notes \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'x-ibm-client-id: default' \
  --header 'x-ibm-client-secret: SECRET' \
  --data '{"title":"zacud","content":"hamxxx"}'
No response received. Causes include a lack of CORS support on the target server, the server being unavailable, or an untrusted certificate being encountered.
Clicking the link below will open the server in a new tab. If the browser displays a certificate issue, you may choose to accept it and return here to test again.
https://localhost:4002/api/Notes

参考

gateway ではなく、アプリケーションに直接アクセスだと登録できる

  • post
curl --request POST \
  --url http://localhost:4001/api/Notes \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'x-ibm-client-id: default' \
  --header 'x-ibm-client-secret: SECRET' \
  --data '{"title":"zacud","content":"hamxxx"}'
  • get
$ curl -XGET http://localhost:4001/api/Notes
[{"title":"zacud","content":"hamezt","id":1},{"title":"zacud","content":"hamxxx","id":2}]
$ 

apiconnect license をコマンドラインで許可する

2017-10-22T10:13:38.716151+00:00 heroku[web.1]: Starting process with command `apic --accept-license --disable-analytics edit`
2017-10-22T10:13:45.950744+00:00 app[web.1]: Express server listening on http://127.0.0.1:55094
2017-10-22T10:14:38.841235+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-10-22T10:14:38.841364+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-10-22T10:14:38.965097+00:00 heroku[web.1]: Process exited with status 137
2017-10-22T10:14:38.979549+00:00 heroku[web.1]: State changed from starting to crashed
  • port を変える必要あり

参考

app.set('port', (process.env.PORT || 5000));