TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

The Dogma of Restful APIs

1 点作者 emptysea大约 2 年前

1 comment

alganet大约 2 年前
This is the dogma of CRUD, popularized by web frameworks. REST says nothing about granularity.<p>&quot;a single endpoint relates to a single entity&quot; is not a REST thing. I understand that for 99% the people they are the same thing, but they&#x27;re actually not.<p>`GET &#x2F;inbox` is not REST though, because it implies that the reply varies according to some authorization header. It messes up the &quot;layered&quot; idea of being able to cache stuff by their identification.<p>`GET &#x2F;inbox&#x2F;:account_set_id` is REST enough. `account_set_id` can be a `session_id`, it doesn&#x27;t matter how you group things, as long as you identify each resource uniquely. It can be a huge resource, containing information about others inside, no problem.<p>You can even have multiple levels of granularity if you want:<p>`GET &#x2F;inbox&#x2F;:some_id` gets all inboxes<p>`GET &#x2F;accounts&#x2F;:acc_id&#x2F;mailboxes&#x2F;threads&#x2F;by-date&#x2F;latest&#x2F;messages&#x2F;by-author&#x2F;first&#x2F;cc&#x2F;0` get the first cc&#x27;d email of the first author of the most recent thread<p>These two can live on the same application, RESTfully side by side. So can resources that fetch multiple stuff:<p>`GET &#x2F;message-fields?list=subject,cc&amp;fromAccounts=123,456&amp;since=2023`<p>If you can name it, you can REST it. You can REST it even if you can&#x27;t quite name it using `POST`.<p>`POST &#x2F;graphql` is REST. It just isn&#x27;t very CRUD-y, and by being a POST, it ignores a lot of the REST benefits (but doesn&#x27;t necessarily contradict them).<p>TL;DR: CRUD frameworks appropriated the REST terminology and made a mess with its meaning.