Hejdaの見る夢

一人前のエンジニアを目指して頑張ったこととかをつらつら書くブログ

Web APIの現場あるある解決特集〜こうして僕たちのAPIは使いやすくなった〜

登壇者

WebAPIの現場あるある解決特集〜こうして僕たちのAPIは使いやすくなった〜

  • web apiの悩み

    • 仕様が統一してない
  • レスポンスにどこまで含む

    • フロントの改修ではなく、APIで改修する??
      • レスポンス加工は留めない
    • APIはリクエストに応じた必要なレスポンスのみを返すことに留める
    • APIから受け取ったデータをどのように加工したり使うかは利用側が決める
    • でも、APIでやったほうがいいもの
      • DBを再度参照するもの
        • DB負荷を考えて
      • 複雑なロジックを用いて取得・判定するデータ
        • 権限系
  • RESTにこだわったほうがいいの?

    • URLを見ただけでは何のAPIか分からない
      • 場合によってはリクエストパラメータで実装したほうがシンプルになる
    • ログインユーザ関連API
      • /api/v1/user/1/withdrow
      • /api/v1/me/whithdrow
    • 結論
      • シンプルで分かりやすいAPI
      • APIで判別出来るデータはリクエストパラメータに含めない
  • 画面に必要なデータはどうするか

    • 1スクリーン1APIコール
      • 利便性が高い
      • APIのリクエストの軽減
      • 例外もある
        • 取得するデータによって
    • 1セーブ1APIコール
  • エラーの返し方
  • ページング用のAPIは必要か
    • デモ
  • まとめ
    • APIのルールを決めて、準拠する
    • 利用側に依存しすぎない
    • シンプルで分かりやすいを追求

dockerのimageのキーボード設定で泣いている話

出来なかったという、ちょっとした小話です。

最近dockerを覚え(≠習得)まして

自前のスクリプトのローカル環境をvagrantのboxから載せ替えたり

werckerのymlをしっかり書いてみてテストが通ってニヤニヤしています。

で、ここ2日ほどハマっているのが「OSのキーボード設定」なのです。

自身でスクリプトやアプリを作る時の基本的な自分ルールとして

  • インフラ作成(所謂LAMP環境)時は公式のrepoを元とし、必ずインフラ作成はコード管理を行う
    • 例えば、vagrantやdockerならpublicやofficialなものを使用
    • コード管理はchefかansibleを使用してます(需要によって替えてる両刀派)

というルールを課しているがゆえに以下の問題にぶち当たって進めないでいる

理由としては

  • officialのイメージがキーボード設定がなされてないこと
    • キーボード設定をするには dpkg-reconfigure keyboard-configuration とかやらないといけないが、ウィザードが立ち上がり、apt-getだと入力待ちになり止まってしまう
    • 参考

みたいな感じです。

解決作はいくつかあって、

  • 他の設定してあるimageを使う
  • キーボード設定だけは目をつむって設定する

は嫌なので、

  • そもそもcmatrixをapt-getでインストールせず、Dockerfile内でmakeする

をするかなぁとか思案中です(´・ω・`)

githubで検索すると結構レポジトリが見つかるので、それに頼ってもいいかもとは思ってますが

やはり自分で構築して公開したいものです(´・ω・`)

冒頭でも書きましたが出来なかったという小話です。

何かの話のネタになれば幸いです。

後日記録

調べていたらキーボード設定をshellで出来るとの記事を発見

Raspberry Pi Raspbian Wheezy(2015-05-05)で最速Wi-Fiセットアップ

これは試してみるのもありかも…

「コンソール上の処理終了通知をslackに投稿する」を書いた裏話

久しぶりにQiitaの記事を書いたので後記録でも。 qiita.com

記事を書き始めたきっかけ

vagrantとansibleでテスト環境を作って検証していた時に、

終わったタイミングを成功、失敗に関わらずとにかく通知して欲しかったため。

itermのtabと画面割を駆使して並列でvagrantを使っていたけど、

ぱっと見どれが終わったのか分かりにくかったのです。

記事に書いた以外の使い方

記事内では ; で繋げて出力結果に関せずにslackに通知をさせているけど、

出力内容を出したい場合は元のスクリプトにパイプラインでshellに渡してあげれば良いです。

alias nm="sh ~/cmd-shell/slack/notify-me.sh"
  • 実行
$ command | nm

しかし、slackに非常に長い通知が来ることが予想されるので

出力結果をまとめるスクリプトを入れた方がいいかも。

アイコンについて

最初はauのCMの一寸法師を使っていたのですが、

何度も通知が来るようになると途端にうざく美人に通知して欲しくなったので、

最近Azureをさわりはじめていることもあってクラウディアさんをお借りました。

通知系なので秘書みたいなものだしいいよね。

そして、秘書は美人につきますね(ㆁᴗㆁ✿)

Warning: Remote connection disconnect. Retrying...の話

最近、macvagrantがおかしい様子…

ローカル開発でvagrantを使っているのですが、最近になって様子がおかしい…

最初のupでは普通に立ち上がるのだけど、halt後のupやsnapshotをロールバックした後のupもコケる様子。

$ vagrant snapshot go first_snap
Powering off machine 3264830a-160b-4bb2-8d06-d5a1fb1f4721
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Restoring snapshot 6ba7eaa2-d91e-4a2f-a1c5-6bf2e0cbda96
Starting restored VM
==> svr03: Checking if box 'bento/centos-6.7' is up to date...
==> svr03: Resuming suspended VM...
==> svr03: Booting VM...
==> svr03: Waiting for machine to boot. This may take a few minutes...
    svr03: SSH address: 127.0.0.1:2201
    svr03: SSH username: vagrant
    svr03: SSH auth method: private key
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
    svr03: Warning: Remote connection disconnect. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase

過去にも同様のとこで悩んでいる方々もちらほら…

Vagrant で default: Warning: Remote connection disconnect. Retrying…

で、解決策としては1回destroyしてまっさらにすればup出来るのだけど、

それだとansibleのrole作成等々でとても不便…

今はboxを変えてみたりして試行錯誤中です(´・ω・`)