3.2. 链接
3.2. 链接 (Links)
另一种常见做法是假定 server 的 URI structure 是众所周知的, 并且可以由 client 计算出来. 在那些对 URI component 和 subcomponent 的存在性, 语法和语义提出要求的规范中, 可以看到这种做法.
虽然这使此类 API 使用起来很方便, 但也会将 client 与 server 紧密耦合. 这种耦合可能成为负担 (例如, 当 server 希望改变 URI 分配方式时).
更灵活的方法是使用嵌入在 representation 或 header field 中的 link (例如 Link 或 Location). 这样, client 不需要知道 server URI space 的结构; 它只需要理解如何发现相关 link 并 dereference 它. 这有时称为 "hypermedia as the engine of application state" 或 "HATEOAS".
更多信息见 [WEB-LINKING], Link header field 见 [RFC8288].