Skip to content

Swift implementation of URI Template (RFC6570)

License

Notifications You must be signed in to change notification settings

kasei/URITemplate

 
 

Repository files navigation

URITemplate

Swift implementation of URI Template (RFC6570).

Installation

CocoaPods is the recommended installation method.

pod 'URITemplate'

Example

Expanding a URI Template

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/"

Determine which variables are in a template

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

Extract the variables used in a given URL

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

The URITemplate library follows the test suite.

We have full support for level 4 of RFC6570 when expanding a template and retrieving the variables in a template.

For extraction of variables from an already expanded template, level 3 is supported.

License

URITemplate is licensed under the MIT license. See LICENSE for more info.

About

Swift implementation of URI Template (RFC6570)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.0%
  • Ruby 2.0%