Robust and performant Swift implementation of RFC6570 URI Template

What's New


  • Allow single-quote as literal, refer RFC errata 6937
  • Add Sendable conformance
  • Do not encode percent-encoded-triplets in reserved or fragment expansion
  • Update test suite
  • Support back to Swift 5.4


A robust and performant Swift 5 implementation of RFC6570 URI Template. Full Level 4 support is provided.

CI Codecov branch

license GitHub release

Getting Started

Swift Package Manager

Add .package(url: "", from: "3.0.0") to your Package.swift dependencies


Template Processing

import ScreamURITemplate

let template = try URITemplate(string:"{owner}/{repository}/traffic/views")
let variables = ["owner":"SwiftScream", "repository":"URITemplate"]
let urlString = try template.process(variables)

When Things Go Wrong

Both 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: "{}/{repository}")
} catch URITemplate.Error.malformedTemplate(let position, let reason) {
    // reason = "Empty Variable Name"
    // position = 29th character

Get variable names used in a template

let template = try URITemplate(string:"{owner}/{repository}/traffic/views")
let variableNames = template.variableNames
// ["owner", "repository"]

Codable Support

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.


  • Swift Tools 5.4.0
View More Packages from this Author


  • None
Last updated: Fri Jan 27 2023 02:09:28 GMT-0500 (GMT-05:00)