URITemplate

URI 模板的 Swift 实现 (RFC6570)。

安装

CocoaPods 是推荐的安装方法。

pod 'URITemplate'

示例

展开 URI 模板

let template = URITemplate(template: "https://api.github.com/repos/{owner}/{repo}/")
let url = template.expand(["owner": "kylef", "repo": "URITemplate.swift"])
=> "https://api.github.com/repos/kylef/URITemplate.swift/"

确定模板中包含哪些变量

let variables = template.variables
=> ["owner", "repo"]

提取给定 URL 中使用的变量

let variables = template.extract("https://api.github.com/repos/kylef/PathKit/")
=> ["owner":"kylef", "repo":"PathKit"]

RFC6570

URITemplate 库遵循 测试套件

在展开模板和检索模板中的变量时,我们完全支持 RFC6570 的级别 4。

对于从已展开的模板中提取变量,我们支持级别 3。

许可

URITemplate 基于 MIT 许可授权。有关更多信息,请参阅 LICENSE