REST 祖师爷 Roy Fielding 说: RPC 就不适合 RESTful 风格。只有超文档适合用 REST - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
httpbin - 协议调试工具
httpstatuses - 协议状态码查询
httpie - cURL-like tool for humans
Fiddler
lambdaq
V2EX    HTTP

REST 祖师爷 Roy Fielding 说: RPC 就不适合 RESTful 风格。只有超文档适合用 REST/h1>
  •  
  •   lambdaq 2022-07-19 10:20:24 +08:00 2244 次点击

    这是一个创建于 1179 天前的主题,其中的信息可能已经有所发展或是发生改变。

    I am getting frustrated by the number of people calling any HTTP-based interface a REST API. Today’s example is the SocialSite REST API. That is RPC. It screams RPC. There is so much coupling on display that it should be given an X rating.

    What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint? In other words, if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period. Is there some broken manual somewhere that needs to be fixed?

    --Roy Fielding, Creator of the term REST

    REST APIs must be hypertext-driven

    https://htmx.org/essays/how-did-rest-come-to-mean-the-opposite-of-rest/

    4 条回复    2022-07-19 11:42:16 +08:00
    baiyi
        1
    baiyi  
       2022-07-19 11:06:16 +08:00
    虽然 HTTP 协议是基于 RESTful 风格设计的,但不是用了 HTTP 协议的 API 就能叫做 REST API 。
    Fielding 一直都不承认现在的 REST API ,认为它们只能叫做 HTTP API 或是 JSON RPC ,还曾经点名过微软的 REST API 。

    文章里提到的超媒体驱动是我认为现在 REST API 最难达到的一点,Github 的 REST API 是我认为最接近的,但它仍然需要文档的帮助。
    在 Fielding 的理念中,难道你访问一个网页,还需要有个网页使用手册来帮助你理解吗?网页有变更,难道要通知用户去查看新的手册吗?这些都是现在 API 的问题。
    在我看来,目前(好几年没关注了,认知停留在 2019 年)的 OpenAPI 或者是 JSON Schema 这些规范提供的描述性格式都不足以达到文档的效果,所以也很难去掉文档的辅助,更别提客户端动态适应 API 的修改了。
    lambdaq
        2
    lambdaq  
    OP
       2022-07-19 11:14:37 +08:00
    @baiyi 其实对于一个 hypertext 来说是这样的。Roy 的理念是从首页入手,所有的增删改查的操作都是可以在首页 hypertext 里找到直接的操作子级 URL 的 。就像 unix 文件系统一样,根目录 / 下可以列表,可以增加,可以删除。

    感觉和他后来做的 WebDAV 就很契合。
    gam2046
        3
    gam2046  
       2022-07-19 11:19:48 +08:00   3
    现阶段,适配 REST API 的只有 OSS 了,功能足够简单,增删改的谓语词也足够用,一切都不言自明。

    其他所有和业务相关的 API ,都无法脱离文档,仅仅靠 REST 那几个谓语词根本无法确定意图。
    lambdaq
        4
    lambdaq  
    OP
       2022-07-19 11:42:16 +08:00
    @gam2046 OSS 这种面向「资源」的场景的确很适合 RESTful 。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     891 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 20ms UTC 20:48 PVG 04:48 LAX 13:48 JFK 16:48
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86