techium

このブログは何かに追われないと頑張れない人たちが週一更新をノルマに技術情報を発信するブログです。もし何か調査して欲しい内容がありましたら、@kobashinG or @muchiki0226 までいただけますと気が向いたら調査するかもしれません。

REST API 設計

REST API 設計

Rails チュートリアルで作成したアプリに REST API を実装するシリーズ。

  • Doorkeeper による OAuth2 認可
  • Grape による REST API 実装
  • Swagger(OpneAPI) を用いたドキュメンテーションの追加
  • Grape Entities を使ったドキュメント中のレスポンス定義

と必要な要素は全て揃った感があるので、REST API の全容を決めていく。

REST API 一覧

必要そうなものを挙げていく。

  • GET /api/v1/users
    • Return all users.
  • GET /api/v1/users/{id}
    • Return user with id.
  • GET /api/v1/users/{id}/following
    • Return following users of user with id.
  • GET /api/v1/users/{id}/followers
    • Return followers of user with id.
  • GET /api/v1/users/{id}/microposts
    • Return microposts of user with id.
  • POST /api/v1/microposts
    • Create a new micropost.
  • DELETE /api/v1/microposts/{id}
    • Destroy micropost with id.
  • GET /api/v1/feed
    • Return feed.
  • POST /api/v1/relationships
    • Create relationship between user with followed_id.
    • param
      • followed_id
        • The ID of the user for whom to be followed.
  • DELETE /api/v1/relationships
    • Destroy relationship between user with followed_id.
    • param
      • followed_id
        • The ID of the user for whom to be unfollowed.

とりあえずこれぐらいか。
ユーザー登録とか削除とかとりあえず動かす上では必須ではないよね。

その他

Reference Documentation — Twitter Developers を参考にしようかと思ったが、

POST friendships/create

あれこれ REST? みたいな。ブラウザで扱いやすいように GET と POST にまとめていくとこうなった的な歴史なのだろうか。
いろんな考察を経てこの形に落ち着いているのだろうから真似した方がいいのかなと思わなくもないがとりあえず自分の思う形で実装してみようかな。(あとで困ったら「あ、あの時。。」と思い返します。

じゃあ完成形は決まったので次回から実装。