| draft-gregorio-uritemplate-02.txt | | draft-gregorio-uritemplate-03.txt | |
| | | | |
| Network Working Group J. Gregorio, Ed. | | Network Working Group J. Gregorio, Ed. | |
| Internet-Draft Google | | Internet-Draft Google | |
| Intended status: Standards Track M. Hadley, Ed. | | Intended status: Standards Track M. Hadley, Ed. | |
|
| Expires: May 29, 2008 Sun Microsystems | | Expires: September 27, 2008 Sun Microsystems | |
| M. Nottingham, Ed. | | M. Nottingham, Ed. | |
| | | | |
| D. Orchard | | D. Orchard | |
| BEA Systems, Inc. | | BEA Systems, Inc. | |
|
| Nov 26, 2007 | | Mar 26, 2008 | |
| | | | |
| URI Template | | URI Template | |
|
| draft-gregorio-uritemplate-02 | | draft-gregorio-uritemplate-03 | |
| | | | |
| Status of this Memo | | Status of this Memo | |
| | | | |
| By submitting this Internet-Draft, each author represents that any | | By submitting this Internet-Draft, each author represents that any | |
| applicable patent or other IPR claims of which he or she is aware | | applicable patent or other IPR claims of which he or she is aware | |
| have been or will be disclosed, and any of which he or she becomes | | have been or will be disclosed, and any of which he or she becomes | |
| aware will be disclosed, in accordance with Section 6 of BCP 79. | | aware will be disclosed, in accordance with Section 6 of BCP 79. | |
| | | | |
| Internet-Drafts are working documents of the Internet Engineering | | Internet-Drafts are working documents of the Internet Engineering | |
| Task Force (IETF), its areas, and its working groups. Note that | | Task Force (IETF), its areas, and its working groups. Note that | |
| | | | |
| skipping to change at page 1, line 39 | | skipping to change at page 1, line 39 | |
| and may be updated, replaced, or obsoleted by other documents at any | | and may be updated, replaced, or obsoleted by other documents at any | |
| time. It is inappropriate to use Internet-Drafts as reference | | time. It is inappropriate to use Internet-Drafts as reference | |
| material or to cite them other than as "work in progress." | | material or to cite them other than as "work in progress." | |
| | | | |
| The list of current Internet-Drafts can be accessed at | | The list of current Internet-Drafts can be accessed at | |
| http://www.ietf.org/ietf/1id-abstracts.txt. | | http://www.ietf.org/ietf/1id-abstracts.txt. | |
| | | | |
| The list of Internet-Draft Shadow Directories can be accessed at | | The list of Internet-Draft Shadow Directories can be accessed at | |
| http://www.ietf.org/shadow.html. | | http://www.ietf.org/shadow.html. | |
| | | | |
|
| This Internet-Draft will expire on May 29, 2008. | | This Internet-Draft will expire on September 27, 2008. | |
| | | | |
| Copyright Notice | | | |
| | | | |
| Copyright (C) The IETF Trust (2007). | | | |
| | | | |
| Abstract | | Abstract | |
| | | | |
| A URI Template is a compact sequence of characters used for the | | A URI Template is a compact sequence of characters used for the | |
| construction of URIs. This specification defines the URI Template | | construction of URIs. This specification defines the URI Template | |
| syntax and the process for expanding a URI Template into a URI, along | | syntax and the process for expanding a URI Template into a URI, along | |
| with guidelines and security considerations for the use of URI | | with guidelines and security considerations for the use of URI | |
| Templates on the Internet. The URI Template syntax allows for the | | Templates on the Internet. The URI Template syntax allows for the | |
| construction of strings that are a superset of URIs, allowing an | | construction of strings that are a superset of URIs, allowing an | |
| implementation to process any URI Template without knowing the | | implementation to process any URI Template without knowing the | |
| | | | |
| skipping to change at page 2, line 20 | | skipping to change at page 2, line 16 | |
| Editorial Note | | Editorial Note | |
| | | | |
| To provide feedback on this Internet-Draft, join the W3C URI mailing | | To provide feedback on this Internet-Draft, join the W3C URI mailing | |
| list (http://lists.w3.org/Archives/Public/uri/) [1]. | | list (http://lists.w3.org/Archives/Public/uri/) [1]. | |
| | | | |
| Table of Contents | | Table of Contents | |
| | | | |
| 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 | | 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 | |
| 1.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 3 | | 1.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 3 | |
| 1.2. Design Considerations . . . . . . . . . . . . . . . . . . 4 | | 1.2. Design Considerations . . . . . . . . . . . . . . . . . . 4 | |
|
| 1.3. Notational Conventions . . . . . . . . . . . . . . . . . . 4 | | 1.3. Applicability . . . . . . . . . . . . . . . . . . . . . . 4 | |
| 2. Characters . . . . . . . . . . . . . . . . . . . . . . . . . . 4 | | 1.4. Notational Conventions . . . . . . . . . . . . . . . . . . 4 | |
| 3. URI Template . . . . . . . . . . . . . . . . . . . . . . . . . 5 | | 2. Characters . . . . . . . . . . . . . . . . . . . . . . . . . . 5 | |
| 3.1. Variables . . . . . . . . . . . . . . . . . . . . . . . . 5 | | 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 5 | |
| 3.2. Template Expansions . . . . . . . . . . . . . . . . . . . 6 | | 4. URI Template . . . . . . . . . . . . . . . . . . . . . . . . . 5 | |
| 3.3. URI Template Substitution . . . . . . . . . . . . . . . . 6 | | 4.1. Variables . . . . . . . . . . . . . . . . . . . . . . . . 5 | |
| 3.3.1. The 'opt' operator . . . . . . . . . . . . . . . . . . 7 | | 4.2. Template Expansions . . . . . . . . . . . . . . . . . . . 6 | |
| 3.3.2. The 'neg' operator . . . . . . . . . . . . . . . . . . 7 | | 4.3. Error Handling . . . . . . . . . . . . . . . . . . . . . . 6 | |
| 3.3.3. The 'prefix' operator . . . . . . . . . . . . . . . . 7 | | 4.4. URI Template Substitution . . . . . . . . . . . . . . . . 7 | |
| 3.3.4. The 'append' operator . . . . . . . . . . . . . . . . 7 | | 4.4.1. ('var') substitution . . . . . . . . . . . . . . . . . 8 | |
| 3.3.5. The 'join' operator . . . . . . . . . . . . . . . . . 7 | | 4.4.2. The 'opt' operator . . . . . . . . . . . . . . . . . . 8 | |
| 3.3.6. The 'listjoin' operator . . . . . . . . . . . . . . . 7 | | 4.4.3. The 'neg' operator . . . . . . . . . . . . . . . . . . 8 | |
| 3.4. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 8 | | 4.4.4. The 'prefix' operator . . . . . . . . . . . . . . . . 9 | |
| 4. Security Considerations . . . . . . . . . . . . . . . . . . . 10 | | 4.4.5. The 'suffix' operator . . . . . . . . . . . . . . . . 9 | |
| 5. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 10 | | 4.4.6. The 'join' operator . . . . . . . . . . . . . . . . . 9 | |
| 6. Appendix A - Parsing URI Template Expansions . . . . . . . . . 10 | | 4.4.7. The 'list' operator . . . . . . . . . . . . . . . . . 10 | |
| 7. Normative References . . . . . . . . . . . . . . . . . . . . . 11 | | 4.5. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 11 | |
| Appendix A. Contributors . . . . . . . . . . . . . . . . . . . . 11 | | 5. Security Considerations . . . . . . . . . . . . . . . . . . . 12 | |
| Appendix B. Revision History . . . . . . . . . . . . . . . . . . 12 | | 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 12 | |
| Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 12 | | 7. Appendix A - Parsing URI Template Expansions . . . . . . . . . 13 | |
| Intellectual Property and Copyright Statements . . . . . . . . . . 13 | | 8. Normative References . . . . . . . . . . . . . . . . . . . . . 13 | |
| | | Appendix A. Contributors . . . . . . . . . . . . . . . . . . . . 14 | |
| | | Appendix B. Revision History . . . . . . . . . . . . . . . . . . 14 | |
| | | Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 15 | |
| | | Intellectual Property and Copyright Statements . . . . . . . . . . 16 | |
| | | | |
| 1. Introduction | | 1. Introduction | |
| | | | |
| A URI Template provides a simple and extensible format for URI | | A URI Template provides a simple and extensible format for URI | |
| construction. A URI Template is a string that contains embedded | | construction. A URI Template is a string that contains embedded | |
| expansions, text marked off in matching braces ('{', '}'), that | | expansions, text marked off in matching braces ('{', '}'), that | |
| denotes a part of the string that is to be substituted by a template | | denotes a part of the string that is to be substituted by a template | |
| processor to produce a URI. A URI Template is transformed into a URI | | processor to produce a URI. A URI Template is transformed into a URI | |
| by substituting the expansions with their calculated value. | | by substituting the expansions with their calculated value. | |
| | | | |
| | | | |
| skipping to change at page 3, line 35 | | skipping to change at page 3, line 35 | |
| | | | |
| A URI Template allows a structural description of URIs while allowing | | A URI Template allows a structural description of URIs while allowing | |
| a consumer of the template to construct a final URI by providing the | | a consumer of the template to construct a final URI by providing the | |
| values of the expansion variables. For example, given the following | | values of the expansion variables. For example, given the following | |
| URI Template: | | URI Template: | |
| | | | |
| http://www.example.com/users/{userid} | | http://www.example.com/users/{userid} | |
| | | | |
| And the following variable value | | And the following variable value | |
| | | | |
|
| userid := fred | | userid := "fred" | |
| | | | |
| The expansion of the URI Template is: | | The expansion of the URI Template is: | |
| | | | |
| http://www.example.com/users/fred | | http://www.example.com/users/fred | |
| | | | |
|
| URI Templates can be used as a machine-readable forms language. By | | Here is an example that constructs a query from multiple variables: | |
| allowing clients to form their own identifiers based on templates | | | |
| given to them by the URI's authority it's possible to construct | | | |
| dynamic systems that use more of the URI than traditional HTML forms. | | | |
| For example: | | | |
| | | | |
|
| http://www.example.org/products/{upc}/buyers?page={page_num} | | http://www.example.com/?{-join|&|query,number} | |
| | | | |
|
| URI Templates can also be used to compose URI-centric protocols | | And the following variables | |
| without impinging on authorities' control of their URI space. For | | | |
| example, there are many emerging conventions for passing around login | | | |
| information between sites using URIs. Forcing people to use a well- | | | |
| known query parameter isn't good practice, but using URI Templates | | | |
| allows different sites to specify local ways of conveying the same | | | |
| information: | | | |
| | | | |
|
| http://auth.example.com/userauth;{return-uri} | | query := "mycelium" | |
| | | number := 100 | |
| | | | |
|
| http://login.example.org/login?back={return-uri} | | The expansion of the URI Template is: | |
| | | | |
| | | http://www.example.com/?query=mycelium&number=100 | |
| | | The template expansion describes in a machine readable manner how the | |
| | | URI is to be constructed. | |
| | | | |
| | | http://www.example.com/?{-join|&|query,number} | |
| | | \____________________/ | |
| | | | | |
| | | | | |
| | | Join 'var=value' for each variable | |
| | | in ['query', 'number'] with '&'. | |
| | | | |
| 1.2. Design Considerations | | 1.2. Design Considerations | |
| | | | |
| The URI Template syntax has been designed to carefully balance the | | The URI Template syntax has been designed to carefully balance the | |
| need for a powerful substitution mechanism with ease of | | need for a powerful substitution mechanism with ease of | |
| implementation and security. The syntax is designed to be easy to | | implementation and security. The syntax is designed to be easy to | |
| parse while at the same time providing enough flexibility to express | | parse while at the same time providing enough flexibility to express | |
|
| many common templating scenarios. On the balance, the template | | many common templating scenarios. | |
| processing is not Turing complete, thus avoiding a number of security | | | |
| issues, ala the billion-laughs attack of XML DTDs. | | | |
| | | | |
| Another consideration was to keep the syntax and processing in-line | | Another consideration was to keep the syntax and processing in-line | |
| with the pre-existing templating schemes present in OpenSearch, WSDL | | with the pre-existing templating schemes present in OpenSearch, WSDL | |
| and WADL. | | and WADL. | |
| | | | |
| The final design consideration was control over the placement of | | The final design consideration was control over the placement of | |
| reserved characters in the URI generated from a URI Template. The | | reserved characters in the URI generated from a URI Template. The | |
| reserved characters in a URI Template can only appear in the non- | | reserved characters in a URI Template can only appear in the non- | |
| expansion text, or in the argument to an operator, both locations are | | expansion text, or in the argument to an operator, both locations are | |
| dictated by the URI Template author. Given the percent-encoding | | dictated by the URI Template author. Given the percent-encoding | |
| rules for variable values this means that the source of all | | rules for variable values this means that the source of all | |
| structure, i.e reserved characters, in a URI generated from a URI | | structure, i.e reserved characters, in a URI generated from a URI | |
| Template is decided by the URI Template author. | | Template is decided by the URI Template author. | |
| | | | |
|
| 1.3. Notational Conventions | | 1.3. Applicability | |
| | | | |
| | | While URI Templates use a notation that is similar to some URI path | |
| | | matching notations in web frameworks, URI Templates were not designed | |
| | | for that use case, nor are they appropriate for that purpose. URI | |
| | | Templates are not URIs, they do not identify an abstract or physical | |
| | | resource, they are not to be treated like URIs, nor should not be | |
| | | used in places where a URI would be expected. | |
| | | | |
| | | 1.4. Notational Conventions | |
| | | | |
| This specification uses the Augmented Backus-Naur Form (ABNF) | | This specification uses the Augmented Backus-Naur Form (ABNF) | |
|
| notation of [RFC4234], including the following core ABNF syntax rules | | notation of [RFC5234], including the following core ABNF syntax rules | |
| defined by that specification: ALPHA (letters) and DIGIT (decimal | | defined by that specification: ALPHA (letters) and DIGIT (decimal | |
| digits). See [RFC3986] for the definitions of the URI-reference, | | digits). See [RFC3986] for the definitions of the URI-reference, | |
| percent-encoded, reserved, and unreserved rules. | | percent-encoded, reserved, and unreserved rules. | |
| | | | |
| The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | | The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", | |
| "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | | "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this | |
| document are to be interpreted as described in [RFC2119]. | | document are to be interpreted as described in [RFC2119]. | |
| | | | |
| 2. Characters | | 2. Characters | |
| | | | |
| | | | |
| skipping to change at page 5, line 20 | | skipping to change at page 5, line 29 | |
| character encoding as the surrounding text. | | character encoding as the surrounding text. | |
| | | | |
| The ABNF notation defines its terminal values to be non-negative | | The ABNF notation defines its terminal values to be non-negative | |
| integers (codepoints) based on the US-ASCII coded character set | | integers (codepoints) based on the US-ASCII coded character set | |
| [ASCII]. Because a URI is a sequence of characters, we must invert | | [ASCII]. Because a URI is a sequence of characters, we must invert | |
| that relation in order to understand the URI syntax. Therefore, the | | that relation in order to understand the URI syntax. Therefore, the | |
| integer values used by the ABNF must be mapped back to their | | integer values used by the ABNF must be mapped back to their | |
| corresponding characters via US-ASCII in order to complete the syntax | | corresponding characters via US-ASCII in order to complete the syntax | |
| rules. | | rules. | |
| | | | |
|
| 3. URI Template | | 3. Terminology | |
| | | | |
|
| A URI Template is a sequence of characters that contains one or more | | o template processor - A program or library that converts a URI | |
| embedded template expansions, see Section 3.2. Each expansion | | Template into a URI. | |
| references one or more variables whose values are used in when | | o template expansion - The text between '{' and '}', including the | |
| | | enclosing brackets. | |
| | | | |
| | | 4. URI Template | |
| | | | |
| | | A URI Template is a sequence of characters that contains any number | |
| | | of embedded template expansions, see Section 4.2. Each expansion | |
| | | references one or more variables whose values are used when | |
| determining the substition value for an expansion. A URI Template | | determining the substition value for an expansion. A URI Template | |
|
| becomes a URI when the template expansions are substituted with their | | becomes a URI when all the template expansions are substituted with | |
| values (see Section 3.3). The generated URI will be a URI-reference, | | their values (see Section 4.4). The generated URI will be a URI- | |
| i.e. either an absolute URI or a relative reference. | | reference, i.e. either an absolute URI or a relative reference. | |
| | | | |
|
| 3.1. Variables | | 4.1. Variables | |
| | | | |
|
| The value of every non-list variable, and the individual values in | | Every variable is either a Unicode string or a list of Unicode | |
| list variables, must come from ( unreserved / pct-encoded ). For | | strings. | |
| variable values that are strings that have characters outside that | | | |
| range, the entire string must be converted into UTF-8 [RFC3629], and | | | |
| then every octet of the UTF-8 string that falls outside of ( | | | |
| unreserved / pct-encoded ) MUST be percent-encoded, as per [RFC3986], | | | |
| section 2.1. | | | |
| | | | |
|
| This does not imply that every variable value can be decoded into a | | A template expansion MAY reference variables that are unknown to the | |
| Unicode string. For example, a variable value may be a binary blob | | template processor. Those variables are 'undefined' and template | |
| that has been percent-encoded before being passed into the template | | expansion takes into consideration 'undefined' variables. | |
| processor. | | Conversely, every variable that he template processor knows about is | |
| | | considered 'defined'. | |
| | | | |
|
| The Unicode Standard [UNIV4] defines various equivalences between | | A variable that contains a string of length zero MUST NOT be | |
| sequences of characters for various purposes. Unicode Standard Annex | | considered 'undefined' by the template processor. A list variable | |
| #15 [UTR15] defines various Normalization Forms for these | | that contains no members, that is of zero length, MUST NOT be | |
| equivalences, in particular Normalization Form C (NFC, Canonical | | considered 'undefined' by the template processor. | |
| Decomposition, followed by Canonical Composition) and Normalization | | | |
| Form KC (NFKC, Compatibility Decomposition, followed by Canonical | | | |
| Composition). Since different Normalized Forms unicode strings will | | | |
| have different UTF-8 represenations it is RECOMMEDED that unicode | | | |
| strings use Normalized Form NFC. | | | |
| | | | |
|
| The meaning of 'defined' for a variable is progamming language and | | Beyond the scope of this specification is the allowable programming | |
| library specific and beyond the scope of this specification. Also | | constructs that can be used for a list variable. For example, a | |
| beyond the scope of this specification is the allowable programming | | Python implementation might allow only built-in list types, or it may | |
| constructs that can be used for a list variable used in the | | allow any iterable to be used as the source for a list variable. | |
| 'listjoin' operator. For example, a Python implementation might | | | |
| allow only built-in list types, or it may allow any iterable to be | | Some variables may be supplied with default values. The default | |
| used as the source for a list variable. | | value must comde from ( unreserved / pct-encoded ). Note that there | |
| | | is no notation for supplying default values to list variables. | |
| | | | |
| A variable may appear in more than one expansion in a URI Template. | | A variable may appear in more than one expansion in a URI Template. | |
|
| The value used for that variable must remain the same for every | | The value used for that variable MUST remain the same for every | |
| template expansion when converting a URI Template into a URI. | | template expansion when converting a URI Template into a URI. | |
| | | | |
|
| 3.2. Template Expansions | | 4.2. Template Expansions | |
| | | | |
| Template expansions are the parameterized components of a URI | | Template expansions are the parameterized components of a URI | |
| Template. A template expansion MUST match the 'expansion' rule. | | Template. A template expansion MUST match the 'expansion' rule. | |
| | | | |
| op = 1*ALPHA | | op = 1*ALPHA | |
| arg = *(reserved / unreserved / pct-encoded) | | arg = *(reserved / unreserved / pct-encoded) | |
|
| var = varname [ '=' vardefault ] | | var = varname [ "=" vardefault ] | |
| vars = var [ *("," var) ] | | vars = var [ *("," var) ] | |
| varname = (ALPHA / DIGIT)*(ALPHA / DIGIT / "." / "_" / "-" ) | | varname = (ALPHA / DIGIT)*(ALPHA / DIGIT / "." / "_" / "-" ) | |
| vardefault = *(unreserved / pct-encoded) | | vardefault = *(unreserved / pct-encoded) | |
| operator = "-" op "|" arg "|" vars | | operator = "-" op "|" arg "|" vars | |
| expansion = "{" ( var / operator ) "}" | | expansion = "{" ( var / operator ) "}" | |
| | | | |
|
| 3.3. URI Template Substitution | | 4.3. Error Handling | |
| | | | |
| | | During template substitution error conditions may arise. The exact | |
| | | circumstances for those errors are described in Section 4.4. When an | |
| | | error occurs the template processor MUST NOT return a URI. It is | |
| | | language specific and beyond the scope of this document how the | |
| | | template processor signals that an error has occured and that a URI | |
| | | will not be generated from the template. | |
| | | | |
| | | 4.4. URI Template Substitution | |
| | | | |
| Template substitution is the process of turning a URI Template into a | | Template substitution is the process of turning a URI Template into a | |
| URI given definitions for the variables used in the template. | | URI given definitions for the variables used in the template. | |
|
| Substitution replaces each expansion with its calculated value. | | Substitution replaces each expansion with its calculated value. A | |
| | | template processor take two inputs, a URI Template and a set of | |
| | | variables, and returns a URI-reference. | |
| | | | |
|
| Every expansion consists of either a variable ('var') or an operator | | Before substitution the template processor MUST convert every | |
| expression. In a variable ('var') expansion, if the variable is | | variable value into a sequence of characters in ( unreserved / pct- | |
| defined and non-empty then substitute the value of the variable, | | encoded ). The template processor does that using the following | |
| otherwise substitute the default value. If no default value is given | | algorithm: The template processor normalizes the string using NFKC, | |
| then substitute with the empty string. | | converts it to UTF-8 [RFC3629], and then every octet of the UTF-8 | |
| | | string that falls outside of ( unreserved ) MUST be percent-encoded, | |
| | | as per [RFC3986], section 2.1. For variables that are lists, the | |
| | | above algorithm is applied to each value in the list. | |
| | | | |
| | | The Unicode Standard [UNIV4] defines various equivalences between | |
| | | sequences of characters for various purposes. Unicode Standard Annex | |
| | | #15 [UTR15] defines various Normalization Forms for these | |
| | | equivalences, in particular Normalization Form KC (NFKC, | |
| | | Compatibility Decomposition, followed by Canonical Composition). | |
| | | Since different Normalized Forms unicode strings will have different | |
| | | UTF-8 represenations the only way to guarantee that template | |
| | | processors will produce the same URI is to require a common | |
| | | Normalized Form. | |
| | | | |
| | | Requiring that all characters outside of ( unreserved ) be percent | |
| | | encoded means that the only characters outside of ( unreserved ) that | |
| | | will appear in the generated URI-reference will come from outside the | |
| | | template expansions in the URI Template or from the argument of a | |
| | | template expansion. This means that the designer of the URI Template | |
| | | determines the placement of reserved characters in the resulting URI, | |
| | | and thus the structure of the resulting generated URI-reference. | |
| | | | |
| If the expansion is an operator then the substitution value is | | If the expansion is an operator then the substitution value is | |
| determined by the given operator. Each operator works only on the | | determined by the given operator. Each operator works only on the | |
| variables that are defined within their expansion. | | variables that are defined within their expansion. | |
| | | | |
|
| 3.3.1. The 'opt' operator | | The result of substitution MUST match the URI-reference rule and | |
| | | SHOULD also match any known rules for the scheme of the resulting | |
| | | URI. | |
| | | | |
|
| If the one or more of the variables are defined and non-empty then | | If a template processor encounters an operator that it does not | |
| substitute the value of 'arg', otherwise substitute the empty string. | | understand then it MUST fail and MUST NOT produce a URI from the URI | |
| | | Template. The list of operators that a template processor knows is | |
| | | not constrained by this specification, that is, later specifications | |
| | | may add new operators. | |
| | | | |
|
| 3.3.2. The 'neg' operator | | Every expansion consists of either a variable ('var') or an operator | |
| | | expression ('operator'), and the rules for how to expand each of | |
| | | these is given below. For every expansion a template MUST have at | |
| | | least one variable name in the template expansion. It is an error if | |
| | | no variables are supplied. All of the variables supplied to a | |
| | | template expansion MAY be undefined and the expansion rules below | |
| | | specify how to process the template expansion in that situation. | |
| | | | |
|
| If all of the variables are un-defined or empty then substitute the | | 4.4.1. ('var') substitution | |
| | | | |
| | | In a variable ('var') expansion, if the variable is defined then | |
| | | substitute the value of the variable, otherwise substitute the | |
| | | default value. If no default value is given then substitute with the | |
| | | empty string. | |
| | | | |
| | | Example: | |
| | | | |
| | | foo := "fred" | |
| | | | |
| | | "{foo}" -> "fred" | |
| | | "{bar=wilma}" -> "wilma" | |
| | | "{baz}" -> "" | |
| | | | |
| | | 4.4.2. The 'opt' operator | |
| | | | |
| | | If each variable is undefined or an empty list then substitute the | |
| | | empty string, otherwise substitute the value of 'arg'. | |
| | | | |
| | | Example: | |
| | | | |
| | | foo := "fred" | |
| | | | |
| | | "{-opt|fred@example.org|foo}" -> "fred@example.org" | |
| | | "{-opt|fred@example.org|bar}" -> "" | |
| | | | |
| | | 4.4.3. The 'neg' operator | |
| | | | |
| | | If each variable is undefined or an empty list then substitute the | |
| value of arg, otherwise substitute the empty string. | | value of arg, otherwise substitute the empty string. | |
| | | | |
|
| 3.3.3. The 'prefix' operator | | Example: | |
| | | | |
|
| The prefix operator MUST only have one variable in its expansion. If | | foo := "fred" | |
| the variable is defined and non-empty then substitute the value of | | | |
| arg followed by the value of the variable, otherwise substitute the | | | |
| empty string. | | | |
| | | | |
|
| 3.3.4. The 'append' operator | | "{-neg|fred@example.org|foo}" -> "" | |
| | | "{-neg|fred@example.org|bar}" -> "fred@example.org" | |
| | | | |
|
| The append operator MUST only have one variable in its expansion. If | | 4.4.4. The 'prefix' operator | |
| the variable is defined and non-empty then substitute the value of | | | |
| the variable followed by the value of arg, otherwise substitute the | | | |
| empty string. | | | |
| | | | |
|
| 3.3.5. The 'join' operator | | The prefix operator MUST only have one variable in its expansion. | |
| | | More than one variable is an error condition. If the variable is | |
| | | undefined or an empty list then substitute the empty string. If the | |
| | | variable is a defined non-list then substitute the value of arg | |
| | | preceeded by the value of the variable. If the variable is a defined | |
| | | list then substitute the concatenation of every list value preceeded | |
| | | by the arg. | |
| | | | |
|
| For each variable that is defined and non-empty create a keyvalue | | Example: | |
| string that is the concatenation of the variable name, "=", and the | | | |
| variable value. Concatenate more than one keyvalue string with | | | |
| intervening values of arg to create the substitution value. | | | |
| | | | |
|
| 3.3.6. The 'listjoin' operator | | foo := "fred" | |
| | | bar := ["fee", "fi", "fo", "fum"] | |
| | | baz := [] | |
| | | | |
| | | "{-prefix|/|foo}" -> "/fred" | |
| | | "{-prefix|/|bar}" -> "/fee/fi/fo/fum" | |
| | | "{-prefix|/|baz}" -> "" | |
| | | "{-prefix|/|qux}" -> "" | |
| | | | |
| | | 4.4.5. The 'suffix' operator | |
| | | | |
| | | The prefix operator MUST only have one variable in its expansion. | |
| | | More than one variable is an error condition. If the variable is | |
| | | undefined or an empty list then substitute the empty string. If the | |
| | | variable is a defined non-list then substitute the value of arg | |
| | | followed by the value of the variable. If the variable is a defined | |
| | | list then substitute the concatenation of every list value followed | |
| | | by the arg. | |
| | | | |
| | | Example: | |
| | | | |
| | | foo := "fred" | |
| | | bar := ["fee", "fi", "fo", "fum"] | |
| | | baz := [] | |
| | | | |
| | | "{-suffix|/|foo}" -> "fred/" | |
| | | "{-suffix|/|bar}" -> "fee/fi/fo/fum/" | |
| | | "{-suffix|/|baz}" -> "" | |
| | | "{-suffix|/|qux}" -> "" | |
| | | | |
| | | 4.4.6. The 'join' operator | |
| | | | |
| | | Supplying a list variable to the join operator is an error. For each | |
| | | variable that is defined and non-empty create a keyvalue string that | |
| | | is the concatenation of the variable name, "=", and the variable | |
| | | value. Concatenate more than one keyvalue string with intervening | |
| | | values of arg to create the substitution value. The order of | |
| | | variables MUST be preserved during substitution. | |
| | | | |
| | | Example: | |
| | | | |
| | | foo := "fred" | |
| | | bar := "barney" | |
| | | baz := "" | |
| | | | |
| | | "{-join|&|foo,bar,baz,qux}" -> "foo=fred&bar=barney&baz=" | |
| | | "{-join|&|bar}" -> "bar=barney" | |
| | | "{-join|&|qux}" -> "" | |
| | | | |
| | | 4.4.7. The 'list' operator | |
| | | | |
| The listjoin operator MUST have only one variable in its expansion | | The listjoin operator MUST have only one variable in its expansion | |
|
| and that variable must be a list. If the list is non-empty then | | and that variable must be a list. More than one variable is an | |
| substitute the concatenation of all the list members with intevening | | error. If the list is non-empty then substitute the concatenation of | |
| values of arg. | | all the list members with intervening values of arg. If the list is | |
| | | empty or the variable is undefined them substitute the empty string. | |
| | | | |
|
| The result of substitution MUST match the URI-reference rule and | | Example: | |
| SHOULD also match any known rules for the scheme of the resulting | | | |
| URI. | | | |
| | | | |
|
| 3.4. Examples | | foo := ["fred", "barney", "wilma"] | |
| | | bar := ["a", "", "c"] | |
| | | baz := ["betty"] | |
| | | qux := [] | |
| | | | |
| | | "{-list|/|foo}" -> "fred/barney/wilma" | |
| | | "{-list|/|bar}" -> "a//c" | |
| | | "{-list|/|baz}" -> "betty" | |
| | | "{-list|/|qux}" -> "" | |
| | | "{-list|/|corge}" -> "" | |
| | | | |
| | | 4.5. Examples | |
| | | | |
| Given the following template variable names and values: | | Given the following template variable names and values: | |
| | | | |
|
| +----------+--------------------+ | | +---------+----------------------------------+ | |
| | Name | Value | | | | Name | Value | | |
|
| +----------+--------------------+ | | +---------+----------------------------------+ | |
| | a | foo | | | | foo | \u03d3 | | |
| | b | bar | | | | bar | fred | | |
| | data | 10,20,30 | | | | baz | 10,20,30 | | |
| | points | ["10","20", "30"] | | | | qux | ["10","20","30"] | | |
| | list0 | [] | | | | corge | [] | | |
| | str0 | | | | | grault | | | |
| | reserved | :/?#[]@!$&'()*+,;= | | | | garply | a/b/c | | |
| | u | \u2654\u2655 | | | | waldo | ben & jerrys | | |
| | a_b | baz | | | | fred | ["fred", "", "wilma"] | | |
| +----------+--------------------+ | | | plugh | ["\u017F\u0307", "\u0073\u0307"] | | |
| | | | 1-a_b.c | 200 | | |
| | | +---------+----------------------------------+ | |
| | | | |
| Table 1 | | Table 1 | |
| | | | |
|
| The name 'foo' has not been defined, the value of 'str0' is the empty | | The variable 'foo' is the unicode character GREEK UPSILON WITH ACUTE | |
| string, and both list0 and points are lists. The variable 'u' is a | | AND HOOK SYMBOL. This character was chosen because it is one of only | |
| string of two unicode characters, the WHITE CHESS KING (0x2654) and | | three characters that has a different normal form for each of the | |
| the WHITE CHESS QUEEN (0x2655). | | four normalization forms (NFC, NFD, NFKC, NFKD). The name 'xyzzy' | |
| | | has not been defined, the value of 'grault' is the empty string. The | |
| | | variables qux, corge, fred, and plugh are lists. | |
| | | | |
| The following URI Templates will be expanded as shown: | | The following URI Templates will be expanded as shown: | |
| | | | |
| ---- | | ---- | |
|
| http://example.org/?q={a} | | http://example.org/?q={bar} | |
| http://example.org/?q=foo | | http://example.org/?q=fred | |
| | | | |
| http://example.org/{foo} | | | |
| http://example.org/ | | | |
| | | | |
| relative/{reserved}/ | | | |
| relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/ | | | |
| | | | |
| http://example.org/{foo=fred} | | | |
| http://example.org/fred | | | |
| | | | |
| http://example.org/{foo=%25}/ | | | |
| http://example.org/%25/ | | | |
| | | | |
|
| /{-prefix|#|foo} | | /{xyzzy} | |
| / | | / | |
| | | | |
|
| ./{-prefix|#|str0} | | http://example.org/?{-join|&|foo,bar,xyzzy,baz} | |
| ./ | | http://example.org/?foo=%CE%8E&bar=fred&baz=10%2C20%2C30 | |
| | | | |
|
| /{-append|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b} |