A robust and performant Swift 6 implementation of RFC6570 URI Template. Full Level 4 support is provided.
Note
Foundation now includes native URI Template support (URL.Template).
Introduced in Swift Foundation 6.2; available on Apple platforms from iOS 26, macOS 26, and peers.
If your deployment target supports this, and you're just looking to expand a template into a URL, you may prefer to use Foundation instead of this library.
Add .package(url: "https://github.com/SwiftScream/URITemplate.git", from: "5.0.0") to your Package.swift dependencies
import ScreamURITemplate
let template = try URITemplate(string:"https://api.github.com/repos/{owner}/{repository}/traffic/views")
let variables = ["owner":"SwiftScream", "repository":"URITemplate"]
let urlString = try template.process(variables)
// https://api.github.com/repos/SwiftScream/URITemplate/traffic/viewsBoth template initialization and processing can fail; throwing a URITemplate.Error
The error cases contain associated values specifying a string reason for the error and the index into the template string that the error occurred.
do {
_ = try URITemplate(string: "https://api.github.com/repos/{}/{repository}")
} catch {
// error.reason = "Empty Variable Name"
// error.position = 29th character
}let template = try URITemplate(string:"https://api.github.com/repos/{owner}/{repository}/traffic/views")
let variableNames = template.variableNames
// ["owner", "repository"]URITemplate implements the Codable protocol, enabling easy serialization to or from JSON objects.
struct HALObject : Codable {
let _links : [String:URITemplate]
}The library is tested against the standard test suite, as well as some additional tests for behavior specific to this implementation. It is intended to keep test coverage as high as possible.