Mastodon
  • Mastodonの使い方
    • Signing up for an account
    • Setting up your profile
    • Posting toots
    • Using the network features
    • Dealing with unwanted content
    • Promoting yourself and others
    • Set your preferences
    • その他の設定
    • Using Mastodon externally
    • Moving or leaving accounts
  • Mastodonの構築
    • マシンの準備
    • ソースからインストール
    • 環境設定
    • オプションのインストール
      • 全文検索
      • 秘匿サービス
      • シングルサインオン
    • セットアップを完了する
    • 開発者向けコマンドラインを利用する
    • 新しいバージョンへアップグレード
    • サーバのバックアップ
    • 新しいマシンへの移行
    • サーバーのスケールアップ
    • モデレーション
    • トラブルシューティング
  • アプリケーションの開発
    • Getting started with the API
    • Playing with public data
    • Obtaining client app access
    • ログイン
    • ガイドラインとベストプラクティス
    • ライブラリ等
  • コントリビューション
    • 技術的情報
    • 開発環境のセットアップ
    • ソースコードの構造
    • ルーティング
  • スペック
    • ActivityPub
    • WebFinger
    • Security
    • Microformats
    • OAuth
  • REST API
    • OAuthスコープ
  • API一覧
    • apps
      • oauth
    • accounts
      • bookmarks
      • favourites
      • mutes
      • blocks
      • domain_blocks
      • filters
      • reports
      • follow_requests
      • endorsements
      • featured_tags
      • preferences
      • suggestions
    • statuses
      • media
      • polls
      • scheduled_statuses
      • streaming
    • timelines
      • conversations
      • lists
      • markers
    • notifications
      • push
    • search
    • instance
      • trends
      • directory
      • custom_emojis
    • admin
    • proofs
    • oembed
  • APIエンティティ
    • Account
    • Activity
    • Admin::Account
    • Admin::Report
    • Application
    • Attachment
    • Card
    • Context
    • Conversation
    • Emoji
    • Error
    • FeaturedTag
    • Field
    • Filter
    • History
    • IdentityProof
    • Instance
    • List
    • Marker
    • Mention
    • Notification
    • Poll
    • Preferences
    • PushSubscription
    • Relationship
    • Report
    • Results
    • ScheduledStatus
    • Source
    • Status
    • Tag
    • Token

ルーティング

いかにしてHTTPメソッドがコントローラやアクションにマップされるのか。

config/routes.rb

ルートの説明

MastodonはRuby on Railsを使用し、ルーターはconfig/routes.rbで規定されます。Ruby on Rails routing guideに細かい説明がありますが、このページではMastodonがいかにしてルーティングするかを簡単に説明します。

ルーティング手順

namespaceはあるコントローラのディレクトリにマップされるためのプレフィクスです。resourcesはその名前空間のディレクトリ内のコントローラにマップされます。scopeはmoduleのコントローラに渡します。例えば、次の短縮されたコードについて考えてみましょう。

namespace :api do
    namespace :v1 do
        resources :statuses, only [:create, :show, :destroy] do
            scope module: :statuses do
                resource :favourite, only: :create
                resource :unfavourite, to: 'favourites#destroy'
                member do
                    get :context
                end
            end
        end
    end
end

config/routes.rb excerpt

最初に利用可能なリソースは:statusesです。これは、:apiとv1という名前空間下にネストされます。結果として/api/v1/statusesにルーティングされます。onlyは特定の許可されたメソッドを定義します。これはapp/controllers/api/v1/statuses_controller.rbのコントローラで定義されています。

/api/v1/statuses内には、追加のリソースが定義された:statusesモジュールへのスコープがあります。そのリソースへのコントローラはapp/controllers/api/v1/statuses/にあります。例えば:favouriteはapp/controllers/api/v1/statuses/favourites_controller.rb内の#createアクションによってハンドルされ、:unfavouriteは同一のコントローラの#destroyアクションでハンドルされます。

このスコープ内にはあらゆるmemberへのカスタムメソッドが定義されています。つまり、全てのstatusはapp/controllers/api/v1/statuses_controller.rbでコントロールされ、GET /api/v1/statuses/:id/contextにマップされます。

利用可能なメソッド

:index

HTTP GETへのマップで、リストに使用します。コントローラ内の#indexアクションによってハンドルされます。

:show

HTTP GETへのマップで、単一のビューに使用します。コントローラ内の#showアクションによってハンドルされます。

:create

HTTP POSTへのマップです。コントローラ内の#createアクションによってハンドルされます。

:update

HTTP PUTへのマップです。コントローラ内の#updateアクションによってハンドルされます。

:destroy

HTTP DELETEへのマップです。コントローラ内の#destroyアクションによってハンドルされます。

.well-known

/.well-known/host-meta

Extensible Resource Descriptor (XRD)です。Webfingerの存在を公表します。

/.well-known/nodeinfo

Maps to NodeInfo 2.0 endpoint at /nodeinfo/2.0, used for advertising software name and version, protocols, usage statistics, and whether registrations are open.

/.well-know/webfinger

Used for discovering ActivityPub actor id. See Spec compliance > WebFinger for more information.

/.well-known/change-password

Maps to account settings page.

/.well-known/keybase-proof-config

Used for integration with Keybase, defining which usernames are acceptable and where proofs may be checked.

The sections below this point are under construction.

Public URIs

  • /users/username = user URI
  • /users/username/remote_follow = remote follow dialog
  • /users/username/statuses/id = status URI
  • /@username = “toots” tab
  • /@username/with_replies = “toots and replies” tab
  • /@username/media = “media” tab
  • /@username/tagged/:hashtag = tagged statuses by user
  • /@username/:status_id = status permalink
  • /@username/:status_id/embed = embeddable version
  • /interact/:status_id = remote interaction dialog
  • /explore = profile directory
  • /explore/:hashtag = profiles with this hashtag in bio
  • /public = public timeline preview
  • /about = landing page
  • /about/more = extended description
  • /terms = terms of service

API

  • /api/oembed
  • /api/proofs
  • /api/v1
    • statuses [create, show, destroy]
      • reblogged_by [index]
      • favourited_by [index]
      • reblog [create]
      • unreblog [POST reblog#destroy]
      • favourite [create]
      • unfavourite [POST favourites#destroy]
      • bookmark [create]
      • unbookmark [POST bookmarks#destroy]
      • mute [create]
      • unmute [POST mutes#destroy]
      • pin [create]
      • unpin [POST pins#destroy]
      • context [GET]
    • timelines
      • home [show]
      • public [show]
      • tag [show]
      • list [show]
    • streaming [index]
    • custom_emojis [index]
    • suggestions [index, destroy]
    • scheduled_statuses [index, show, update, destroy]
    • preferences [index]
    • conversations [index, destroy]
      • read [POST]
    • media [create, update]
    • blocks [index]
    • mutes [index]
    • favourites [index]
    • bookmarks [index]
    • reports [create]
    • trends [index]
    • filters [index, create, show, update, destroy]
    • endorsements [index]
    • markers [index, create]
    • apps [create]
      • verify_credentials [credentials#show]
    • instance [show]
      • peers [index]
      • activity [show]
    • domain_blocks [show, create, destroy]
    • directory [show]
    • follow_requests [index]
      • authorize [POST]
      • reject [POST]
    • notifications [index, show]
      • clear [POST]
      • dismiss [POST]
    • accounts
      • verify_credentials [GET credentials#show]
      • update_credentials [PATCH credentials#update]
      • search [show (search#index)]
      • relationships [index]
    • accounts [create, show]
      • statuses [index accounts/statuses]
      • followers [index accounts/follower_accounts]
      • following [index accounts/following_accounts]
      • lists [index accounts/lists]
      • identity_proofs [index accounts/identity_proofs]
      • follow [POST]
      • unfollow [POST]
      • block [POST]
      • unblock [POST]
      • mute [POST]
      • unmute [POST]
      • pin [POST]
      • unpin [POST]
    • lists [index, create, show, update, destroy]
      • accounts [POST accounts/pins#destroy]
    • featured_tags [index, create, destroy]
      • suggestions [GET suggestions#index]
    • polls [create, show]
      • votes [create polls/votes]
    • push
      • subscription [create, show, update, destroy]
    • admin
      • accounts [index, show]
        • enable [POST]
        • unsilence [POST]
        • unsuspend [POST]
        • approve [POST]
        • reject [POST]
        • action [create account_actions]
      • reports [index, show]
        • assign_to_self [POST]
        • unassign [POST]
        • reopen [POST]
        • resolve [POST]
  • /api/v2
    • search [GET search#index]

最終更新 February 12, 2020 · このページを改善する
他の言語: English

Merch

Tシャツとステッカー(英語)

Mastodonに参加しよう · ブログ · ·

ソースコード · CC BY-SA 4.0 · インプリント