Skip to content

Commit 856bf24

Browse files
committed
update: rest
1 parent 4fe7115 commit 856bf24

File tree

11 files changed

+17
-25
lines changed

11 files changed

+17
-25
lines changed

content/posts/rest-apis.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ tags = ["REST"]
88
- REST API 的设计原则
99
- Richardson maturity model (RMM) 如何帮助理解 REST 的优势和设计原则
1010
- REST API 中资源(resource)和端点(endpoints)设计的概念
11-
- 使用 HTTP 请求方法(verb)和HTTP状态码(status code)来创建高解释性的REST API
12-
- 为REST API 设计高质量的载荷(payload)和URL查询参数(query parameters)
1311

1412
表达性状态转移 representational state transfer (REST) 描述了一种通过网络进行通信的应用程序架构风格.
1513
最初, REST 的概念包含了一组用于设计分布式、可扩展 Web 应用的约束条件.
@@ -145,17 +143,17 @@ HATEOAS 是 REST API 设计中的一种范式(paradigm), 它强调可发现性.
145143

146144
提供关联链接可以使 API 具有可导航性, 更易于使用, 因为每个资源都会附带与之交互所需的所有 URL.
147145
然而在实际中, 许多 API 并没有这样实现, 原因包括:
148-
1. 超链接提供的信息在 API 文档中已经可用
146+
- 超链接提供的信息在 API 文档中已经可用
149147
- 实际上, OpenAPI 规范中包含的信息比单独为特定资源提供的相关链接列表要丰富和结构化得多
150-
2. 不总是清楚应该返回哪些链接
148+
- 不总是清楚应该返回哪些链接
151149
- 不同用户拥有不同的权限和角色, 可以执行不同操作和访问不同资源
152150
- 例如,CoffeeMesh API 的外部用户可以使用 `POST /orders` 下单, 也可以使用 `GET /orders/{order_id}` 查询订单详情, 但不能使用 `DELETE /orders/{order_id}` 删除订单, 因为该接口仅限内部用户
153151
- 如果 HATEOAS 的目标是让 API 可以从单一入口导航, 那么向外部用户返回他们无法使用的 DELETE 链接显然没有意义
154152
- 因此, 需要根据用户权限返回不同的相关链接列表, 但这会增加 API 设计和实现的复杂性, 并将授权层与 API 层耦合
155-
3. 资源状态可能限制某些操作
153+
- 资源状态可能限制某些操作
156154
- 例如, `POST /orders/1234/cancel` 只能在活跃订单上调用, 而无法对已取消订单调用
157155
- 这种不确定性会增加遵循 HATEOAS 原则的接口设计和实现难度
158-
4. 响应负载可能过大
156+
- 响应负载可能过大
159157
- 在一些 API 中, 相关链接列表可能非常庞大, 使响应体变大, 从而影响 API 性能, 以及对网络连接较差的小设备的可靠性
160158

161159
在设计自己的 API 时, 可以根据实际情况决定是否遵循 HATEOAS 原则, 在某些情况下是有用的, 例如:

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<span class="text-sm font-medium">GitHub</span>
5050
</a><a href=mailto:[email protected] target=_blank rel="noopener noreferrer" class="bg-muted text-muted-foreground hover:text-primary hover:bg-primary/10 focus:ring-primary/20 inline-flex items-center gap-2 rounded-lg px-3 py-2 transition-all duration-300 ease-out hover:-translate-y-0.5 hover:scale-105 focus:ring-2 focus:outline-none" title=Email><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-label="Email"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22.0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v10a2 2 0 002 2z"/></svg>
5151
<span class="text-sm font-medium">Email</span></a></div></div></div></div></section><section class=post-list><div class="mb-6 flex items-center justify-between"><h2 class="text-foreground text-2xl font-bold">Recent Posts</h2></div><div class=space-y-4><article class=group><a href=/posts/designing-and-building-rest-apis/ class=block><div class="bg-card border-border hover:bg-primary/5 hover:border-primary/20 focus:ring-primary/20 relative flex flex-col overflow-hidden rounded-xl border transition-all duration-300 ease-out hover:-translate-y-1 hover:scale-[1.02] hover:shadow-lg focus:ring-2 focus:outline-none min-h-[200px]"><div class="block md:hidden"><div class="aspect-[2/1] overflow-hidden"><div class="from-indigo-500/20 to-purple-500/10 relative aspect-[2/1] overflow-hidden bg-gradient-to-br" style="background-blend-mode:overlay;background-color:color-mix(in srgb,var(--color-primary) 15%,transparent)"><div class="absolute inset-0"><div class="absolute left-[20%] top-[20%] h-5 w-5 rotate-45 border-2 border-white/80 bg-white/15"></div><div class="absolute right-[25%] top-[25%] h-4 w-4 rotate-12 border border-white/70 bg-white/12"></div><div class="absolute left-[30%] bottom-[30%] h-3 w-3 rotate-60 border border-white/60 bg-white/10"></div><div class="absolute right-[20%] bottom-[20%] h-4 w-4 rotate-30 border border-white/65 bg-white/13"></div><div class="absolute left-[45%] top-[45%] h-2 w-2 rotate-45 border border-white/50 bg-white/8"></div><div class="absolute left-[15%] top-[40%] h-0.5 w-8 rotate-45 bg-white/40"></div><div class="absolute right-[15%] top-[35%] h-0.5 w-6 rotate-12 bg-white/35"></div><div class="absolute left-[40%] bottom-[15%] h-0.5 w-5 -rotate-30 bg-white/30"></div><div class="absolute top-[35%] right-[40%] h-2 w-2 rounded-full bg-white/35"></div><div class="absolute bottom-[40%] left-[35%] h-1.5 w-1.5 rounded-full bg-white/30"></div><div class="absolute top-[50%] left-[50%] h-1 w-1 rounded-full bg-white/25"></div></div></div></div></div><div class="absolute top-0 right-0 hidden h-full w-80 transition-opacity duration-300 group-hover:opacity-90 md:block"><div class="h-full w-full"><div class="from-indigo-500/20 to-purple-500/10 relative h-full w-full overflow-hidden bg-gradient-to-br" style="background-blend-mode:overlay;background-color:color-mix(in srgb,var(--color-primary) 15%,transparent)"><div class="absolute inset-0"><div class="absolute left-[20%] top-[20%] h-5 w-5 rotate-45 border-2 border-white/80 bg-white/15"></div><div class="absolute right-[25%] top-[25%] h-4 w-4 rotate-12 border border-white/70 bg-white/12"></div><div class="absolute left-[30%] bottom-[30%] h-3 w-3 rotate-60 border border-white/60 bg-white/10"></div><div class="absolute right-[20%] bottom-[20%] h-4 w-4 rotate-30 border border-white/65 bg-white/13"></div><div class="absolute left-[45%] top-[45%] h-2 w-2 rotate-45 border border-white/50 bg-white/8"></div><div class="absolute left-[15%] top-[40%] h-0.5 w-8 rotate-45 bg-white/40"></div><div class="absolute right-[15%] top-[35%] h-0.5 w-6 rotate-12 bg-white/35"></div><div class="absolute left-[40%] bottom-[15%] h-0.5 w-5 -rotate-30 bg-white/30"></div><div class="absolute top-[35%] right-[40%] h-2 w-2 rounded-full bg-white/35"></div><div class="absolute bottom-[40%] left-[35%] h-1.5 w-1.5 rounded-full bg-white/30"></div><div class="absolute top-[50%] left-[50%] h-1 w-1 rounded-full bg-white/25"></div></div></div></div></div><div class="absolute top-0 right-0 hidden h-full w-80 opacity-0 transition-opacity duration-300 group-hover:opacity-100 md:block bg-gradient-to-l from-primary/5"></div><div class="relative z-10 flex flex-1 flex-col p-6 md:pr-[21rem]"><h3 class="text-foreground group-hover:text-primary mb-4 text-lg font-semibold leading-tight transition-colors duration-200">Designing and Building REST APIs</h3><p class="text-muted-foreground mb-4 text-sm leading-relaxed line-clamp-2">这篇文章延续之前微服务的内容, 将介绍关于 REST API 的以下几个方面:
52-
REST API 的设计原则 Richardson maturity model (RMM) 如何帮助理解 REST 的优势和设计原则 REST API 中资源(resource)和端点(endpoints)设计的概念 使用 HTTP 请求</p><div class="mt-auto text-sm text-muted-foreground"><div class="flex items-center gap-3"><div class="flex items-center gap-1.5"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-label="Published on"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
52+
REST API 的设计原则 Richardson maturity model (RMM) 如何帮助理解 REST 的优势和设计原则 REST API 中资源(resource)和端点(endpoints) …</p><div class="mt-auto text-sm text-muted-foreground"><div class="flex items-center gap-3"><div class="flex items-center gap-1.5"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-label="Published on"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
5353
<time datetime=2025-08-17 class=font-medium>August 17, 2025</time></div><div class="flex items-center gap-1.5"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-label="Reading time"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
5454
<span class=font-medium>8 minute</span></div></div><div class="flex flex-wrap items-center gap-1.5 mt-2"><span class="bg-muted/50 border-muted/30 flex items-center gap-1 rounded-md border px-2 py-1"><span class=font-medium>REST</span></span></div></div></div></div></a></article><article class=group><a href=/posts/intorduce-uuid/ class=block><div class="bg-card border-border hover:bg-primary/5 hover:border-primary/20 focus:ring-primary/20 relative flex flex-col overflow-hidden rounded-xl border transition-all duration-300 ease-out hover:-translate-y-1 hover:scale-[1.02] hover:shadow-lg focus:ring-2 focus:outline-none min-h-[200px]"><div class="block md:hidden"><div class="aspect-[2/1] overflow-hidden"><div class="from-teal-500/20 to-green-500/10 relative aspect-[2/1] overflow-hidden bg-gradient-to-br" style="background-blend-mode:overlay;background-color:color-mix(in srgb,var(--color-primary) 15%,transparent)"><div class="absolute inset-0"><div class="absolute left-[15%] top-[20%] rotate-45"><div class="h-0 w-0 border-l-[10px] border-r-[10px] border-b-[16px] border-l-transparent border-r-transparent border-b-white/80"></div></div><div class="absolute right-[20%] top-[15%] rotate-12"><div class="h-0 w-0 border-l-[8px] border-r-[8px] border-b-[12px] border-l-transparent border-r-transparent border-b-white/70"></div></div><div class="absolute left-[25%] bottom-[25%] -rotate-30"><div class="h-0 w-0 border-l-[6px] border-r-[6px] border-b-[10px] border-l-transparent border-r-transparent border-b-white/60"></div></div><div class="absolute right-[15%] bottom-[20%] rotate-60"><div class="h-0 w-0 border-l-[7px] border-r-[7px] border-b-[11px] border-l-transparent border-r-transparent border-b-white/65"></div></div><div class="absolute left-[45%] top-[40%] -rotate-15"><div class="h-0 w-0 border-l-[5px] border-r-[5px] border-b-[8px] border-l-transparent border-r-transparent border-b-white/50"></div></div><div class="absolute right-[35%] top-[35%] h-2 w-2 rounded-full bg-white/40"></div><div class="absolute left-[40%] bottom-[35%] h-1.5 w-1.5 rounded-full bg-white/35"></div><div class="absolute right-[45%] bottom-[45%] h-1 w-1 rounded-full bg-white/30"></div><div class="absolute top-[30%] left-[30%] h-0.5 w-6 rotate-45 bg-white/25"></div><div class="absolute bottom-[30%] right-[30%] h-0.5 w-4 -rotate-30 bg-white/20"></div></div></div></div></div><div class="absolute top-0 right-0 hidden h-full w-80 transition-opacity duration-300 group-hover:opacity-90 md:block"><div class="h-full w-full"><div class="from-teal-500/20 to-green-500/10 relative h-full w-full overflow-hidden bg-gradient-to-br" style="background-blend-mode:overlay;background-color:color-mix(in srgb,var(--color-primary) 15%,transparent)"><div class="absolute inset-0"><div class="absolute left-[15%] top-[20%] rotate-45"><div class="h-0 w-0 border-l-[10px] border-r-[10px] border-b-[16px] border-l-transparent border-r-transparent border-b-white/80"></div></div><div class="absolute right-[20%] top-[15%] rotate-12"><div class="h-0 w-0 border-l-[8px] border-r-[8px] border-b-[12px] border-l-transparent border-r-transparent border-b-white/70"></div></div><div class="absolute left-[25%] bottom-[25%] -rotate-30"><div class="h-0 w-0 border-l-[6px] border-r-[6px] border-b-[10px] border-l-transparent border-r-transparent border-b-white/60"></div></div><div class="absolute right-[15%] bottom-[20%] rotate-60"><div class="h-0 w-0 border-l-[7px] border-r-[7px] border-b-[11px] border-l-transparent border-r-transparent border-b-white/65"></div></div><div class="absolute left-[45%] top-[40%] -rotate-15"><div class="h-0 w-0 border-l-[5px] border-r-[5px] border-b-[8px] border-l-transparent border-r-transparent border-b-white/50"></div></div><div class="absolute right-[35%] top-[35%] h-2 w-2 rounded-full bg-white/40"></div><div class="absolute left-[40%] bottom-[35%] h-1.5 w-1.5 rounded-full bg-white/35"></div><div class="absolute right-[45%] bottom-[45%] h-1 w-1 rounded-full bg-white/30"></div><div class="absolute top-[30%] left-[30%] h-0.5 w-6 rotate-45 bg-white/25"></div><div class="absolute bottom-[30%] right-[30%] h-0.5 w-4 -rotate-30 bg-white/20"></div></div></div></div></div><div class="absolute top-0 right-0 hidden h-full w-80 opacity-0 transition-opacity duration-300 group-hover:opacity-100 md:block bg-gradient-to-l from-primary/5"></div><div class="relative z-10 flex flex-1 flex-col p-6 md:pr-[21rem]"><h3 class="text-foreground group-hover:text-primary mb-4 text-lg font-semibold leading-tight transition-colors duration-200">Intorduce UUID</h3><p class="text-muted-foreground mb-4 text-sm leading-relaxed line-clamp-2">UUID(Universally Unique Identifier, 通用唯一标识符) 是一种标准化的128位标识符, 用于在分布式系统中生成几乎不会重复的唯一 ID. 最早于 IETF 制定为 RFC 4122 标准, 保证在不同机器、不同时间生成的 ID 也能保持全局唯一.</p><div class="mt-auto text-sm text-muted-foreground"><div class="flex items-center gap-3"><div class="flex items-center gap-1.5"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-label="Published on"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
5555
<time datetime=2025-08-16 class=font-medium>August 16, 2025</time></div><div class="flex items-center gap-1.5"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-label="Reading time"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>

public/index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/index.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
&lt;li>REST API 的设计原则&lt;/li>
44
&lt;li>Richardson maturity model (RMM) 如何帮助理解 REST 的优势和设计原则&lt;/li>
55
&lt;li>REST API 中资源(resource)和端点(endpoints)设计的概念&lt;/li>
6-
&lt;li>使用 HTTP 请求方法(verb)和HTTP状态码(status code)来创建高解释性的REST API&lt;/li>
7-
&lt;li>为REST API 设计高质量的载荷(payload)和URL查询参数(query parameters)&lt;/li>
86
&lt;/ul>
97
&lt;p>表达性状态转移 representational state transfer (REST) 描述了一种通过网络进行通信的应用程序架构风格.
108
最初, REST 的概念包含了一组用于设计分布式、可扩展 Web 应用的约束条件.

0 commit comments

Comments
 (0)