uritemplate

Implements RFC 6570 (URI Template)

Members

Aliases

VariableCallback
alias VariableCallback = const(URIVariable) delegate(string variableName) @(safe)

Callback to resolve a URIVariable by a given variable name. The variable name is always resolved to a simple string and the returned value should not be encoded or otherwise processed for the URI. To conform to RFC 6570 the callback MUST always produce the same variables for any given variable name. The values MUST be determined before template expansion.

Classes

TemplateURIFormatException
class TemplateURIFormatException

Exception thrown on malformed URI templates

Functions

expandTemplateURIString
string expandTemplateURIString(string templateUri, VariableCallback resolveVariable, bool strict)
string expandTemplateURIString(string templateUri, URIVariable[string] variables, bool strict)
string expandTemplateURIString(string templateUri, string[string] variables, bool strict)

Expands a URI template as defined in RFC 6570.

expandTemplateURIVariable
string expandTemplateURIVariable(string templateString, VariableCallback resolveVariable, bool strict, size_t index)
string expandTemplateURIVariable(string templateString, URIVariable[string] variables, bool strict, size_t index)
string expandTemplateURIVariable(string templateString, string[string] variables, bool strict, size_t index)
string expandTemplateURIVariable(string templateString, typeof(null) variables, bool strict, size_t index)

Expands a variable template part of a URI template as defined in RFC 6570.

isValidTemplateURILiteral
bool isValidTemplateURILiteral(string literal, size_t errorIndex)

Checks if the given literal parameter is valid according to RFC 6570 section 2.1.

isValidTemplateURIVariableName
bool isValidTemplateURIVariableName(string varname, size_t errorIndex)

Checks if the given literal parameter is valid according to RFC 6570 section 2.3.

validateTemplateURILiteral
void validateTemplateURILiteral(string literal, size_t index)

Checks if the given literal parameter is valid according to RFC 6570 section 2.1.

validateTemplateURIVariableName
void validateTemplateURIVariableName(string varname, size_t index)

Checks if the given literal parameter is valid according to RFC 6570 section 2.3.

Structs

URIVariable
struct URIVariable

Tagged union for template URI variables. Implementation tags the length of the arrays for the type.

Examples

import uritemplate;

string uriTemplate = "https://cool.webfreak.org/{user}/profile{?fields*}";

assert(uriTemplate.expandTemplateURIString([
	"user": URIVariable("bob"),
	"fields": URIVariable([
		"address", "name", "birthday"
	])
]) == "https://cool.webfreak.org/bob/profile?fields=address&fields=name&fields=birthday");

assert(uriTemplate.expandTemplateURIString([
	"user": URIVariable(["bob!", "Straße"]),
	"fields": URIVariable([
		"address", "name", "birthday"
	])
]) == "https://cool.webfreak.org/bob%21,Stra%C3%9Fe/profile?fields=address&fields=name&fields=birthday");

Meta