Mastodon
  • 什么是 Mastodon?
  • 使用 Mastodon
    • 注册帐户
    • 设置你的个人资料
    • 在你的账户发布内容
    • 使用网络功能
    • 处理不想看到的内容
    • 推广你和他人
    • 进行偏好设置
    • 更多设置
    • 在站点外使用 Mastodon
    • 迁移或离开账户
    • 运行你自己的站点
  • 运营 Mastodon
    • 准备你的服务器
    • 从源代码安装
    • 配置你的环境
    • 安装可选功能
      • 对象存储
      • 洋葱服务
      • 验证码
      • 单点登录
    • 配置全文搜索
    • 设置你的新实例
    • 使用管理 CLI
    • 升级到新版本
    • 备份你的服务器
    • 迁移到新机器
    • 扩大你的站点规模
    • 审核操作
    • 故障排除
      • 数据库索引损坏
    • 用户组
  • 开发 Mastodon 应用
    • API 入门指南
    • 使用公开数据
    • 获取客户端应用访问权限
    • 使用帐户登录
    • 库与实现
  • 向 Mastodon 项目做贡献
    • 技术概览
    • 设置开发环境
    • 代码结构
    • 路由
    • 漏洞赏金与责任披露
  • 遵循的标准
    • ActivityPub
    • WebFinger
    • 安全性
    • Microformats
    • OAuth
    • Bearcaps
  • REST API
    • Datetime 格式
    • 指南与最佳实践
    • OAuth 令牌
    • OAuth 作用域
    • 速率限制
  • API 方法
    • apps
      • oauth
      • emails
    • accounts
      • bookmarks
      • favourites
      • mutes
      • blocks
      • domain_blocks
      • filters
      • reports
      • follow_requests
      • endorsements
      • featured_tags
      • preferences
      • followed_tags
      • suggestions
      • tags
    • profile
    • statuses
      • media
      • polls
      • scheduled_statuses
    • timelines
      • conversations
      • lists
      • markers
      • streaming
    • grouped notifications
    • notifications
      • push
    • search
    • instance
      • trends
      • directory
      • custom_emojis
      • announcements
    • admin
      • accounts
      • canonical_email_blocks
      • dimensions
      • domain_allows
      • domain_blocks
      • email_domain_blocks
      • ip_blocks
      • measures
      • reports
      • retention
      • trends
    • proofs
    • oembed
  • API 实体
    • Account
    • AccountWarning
    • Admin::Account
    • Admin::CanonicalEmailBlock
    • Admin::Cohort
    • Admin::Dimension
    • Admin::DomainAllow
    • Admin::DomainBlock
    • Admin::EmailDomainBlock
    • Admin::Ip
    • Admin::IpBlock
    • Admin::Measure
    • Admin::Report
    • Announcement
    • Appeal
    • Application
    • Context
    • Conversation
    • CustomEmoji
    • DomainBlock
    • Error
    • ExtendedDescription
    • FamiliarFollowers
    • FeaturedTag
    • Filter
    • FilterKeyword
    • FilterResult
    • FilterStatus
    • IdentityProof
    • Instance
    • List
    • Marker
    • MediaAttachment
    • Notification
    • NotificationPolicy
    • NotificationRequest
    • Poll
    • Preferences
    • PreviewCard
    • PreviewCardAuthor
    • PrivacyPolicy
    • Reaction
    • Relationship
    • RelationshipSeveranceEvent
    • Report
    • Role
    • Rule
    • ScheduledStatus
    • Search
    • Status
    • StatusEdit
    • StatusSource
    • Suggestion
    • Tag
    • TermsOfService
    • Token
    • Translation
    • V1::Filter
    • V1::Instance
    • V1::NotificationPolicy
    • WebPushSubscription

路由

HTTP 方法如何映射到控制器与操作。

    • 路由说明
      • 路由的构建方式
      • 可用方法
    • .well-known
      • /.well-known/host-meta
      • /.well-known/nodeinfo
      • /.well-known/webfinger
      • /.well-known/change-password
      • /.well-known/keybase-proof-config
    • 公开 URI
    • API
config/routes.rb

路由说明

Mastodon 使用 Ruby on Rails,它在 config/routes.rb 中定义其路由配置。本页只解释 Mastodon 如何处理路由的基础知识,你可以查看 Ruby on Rails 路由指南 以获取更详细的信息。

路由的构建方式

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 摘录

第一个可用的资源是 :statuses,它嵌套在 :api 和 :v1 命名空间下。因此,生成的 HTTP 路由将是 /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 定义了一个自定义方法,或者换句话说,对于任何要由 app/controllers/api/v1/statuses_controller.rb 控制的状态,该方法都映射到 GET /api/v1/statuses/:id/context 并且由该控制器中定义的 :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

可扩展资源描述符 (XRD)。 声明 Webfinger 的存在。

/.well-known/nodeinfo

映射到 /nodeinfo/2.0 的 NodeInfo 2.0 端点,用于声明软件名称和版本、协议、使用统计信息以及是否开放注册。

/.well-known/webfinger

用于发现 ActivityPub 行为体 ID。有关更多信息,请查看 对 > WebFinger 的合规性说明。

/.well-known/change-password

映射到帐户设置页面。

/.well-known/keybase-proof-config

用于与 Keybase 集成,定义哪些用户名可接受以及可以在哪里检查证明。

以下部分正在建设中。

公开 URI

  • /users/username = 用户 URI
  • /users/username/remote_follow = 外站关注对话框
  • /users/username/statuses/id = 嘟文 URI
  • /@username = “嘟文”选项卡
  • /@username/with_replies = “嘟文与回复”选项卡
  • /@username/media = “媒体”选项卡
  • /@username/tagged/:hashtag = 用户标记的嘟文
  • /@username/:status_id = 嘟文永久链接
  • /@username/:status_id/embed = 可嵌入版本
  • /interact/:status_id = 外站交互对话框
  • /explore = 用户目录
  • /explore/:hashtag = 简介中包含此标签的用户
  • /public = 公共时间线预览
  • /about = 落地页
  • /about/more = 详细描述
  • /terms = 服务条款

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]

翻译状态: 本文是英文页面 Routes 的翻译,最后翻译时间:2025-04-21,点击这里可以查看翻译后页面的改动。

最后更新于 April 21, 2025 · 改进此页面
也可在此找到: English

赞助商

Dotcom-Monitor LoadView Stephen Tures Swayable SponsorMotion

加入Mastodon · 博客 ·

查看源代码 · CC BY-SA 4.0 · 版权信息