API v3 仕様策定

参照

Express response に専用functionを追加

まだ動かしてない。実装イメージ。 タイプチェックは実装時に追加。

express.response.apiv3 = function(obj) { // not arrow function this.json({ oK: true, data: { ...obj, }, }); }; express.response.apiv3Err = function(status, errors) { // not arrow function this.status(status).json({ oK: false, status, errors, }); };

// 成功時 res.apiv3({ user: { id: 1, name: 'John' } }); // response { ok: true, data: { user: { id: 1, name: 'John', } } }
// エラー時 res.apiv3Err(new Error('err example')); // response { ok: false, status: 403, errors: [ { message: 'err example', }, ], }

CRUD

  • GET /groups - グループのリストを取得する
  • GET /groups/12 - 指定したグループの情報を取得する
  • GET /groups/12/users - 指定したグループのユーザーのリストを取得する
  • POST /groups - 新しいグループを作成する
  • PUT /groups/12 - グループ #12 を更新する
  • DELETE /groups/12 - グループ #12 を削除する

フィルター

  • GET /groups?name=exmaple

ソート

  • +昇順
  • -降順
  • GET /groups?sort=-updated_at

フィールドの指定

  • GET /groups?fields=id,name,createdAt

ページング

  • GET /groups?page=3

その他

  • access token?
  • rate limit?
  • X-HTTP-Method-Override? (get, post しか使えない人のため)
  • GROWIエラーコード決める?