# Class UriTemplate (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.UriTemplate)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.UriTemplate)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.UriTemplate)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.UriTemplate)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.UriTemplate)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.UriTemplate)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.UriTemplate)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.UriTemplate)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.UriTemplate)

    public class UriTemplate

Expands URI Templates.

This class supports URI Template Level 1, partial support for Levels 2 and 3, and Level 4
composite templates as described in: [RFC 6570](http://tools.ietf.org/html/rfc6570).

Specifically, for the variables: var := "value" list := \["red", "green", "blue"\] keys :=
\[("semi", ";"),("dot", "."),("comma", ",")\]

The following templates results in the following expansions: {var} -\> value {list} -\>
red,green,blue {list*} -\> red,green,blue {keys} -\> semi,%3B,dot,.,comma,%2C {keys* } -\>
semi=%3B,dot=.,comma=%2C {+list} -\> red,green,blue {+list*} -\> red,green,blue {+keys} -\>
semi,;,dot,.,comma,, {+keys*} -\> semi=;,dot=.,comma=, {#list} -\> #red,green,blue {#list\*} -\>

# red,green,blue {#keys} -\> #semi,;,dot,.,comma,, {#keys\*} -\> #semi=;,dot=.,comma=, X{.list} -\>

X.red,green,blue X{.list*} -\> X.red.green.blue X{.keys} -\> X.semi,%3B,dot,.,comma,%2C X{.keys* }
-\> X.semi=%3B.dot=..comma=%2C {/list} -\> /red,green,blue {/list*} -\> /red/green/blue {/keys} -\>
/semi,%3B,dot,.,comma,%2C {/keys* } -\> /semi=%3B/dot=./comma=%2C {;list} -\> ;list=red,green,blue
{;list*} -\> ;list=red;list=green;list=blue {;keys} -\> ;keys=semi,%3B,dot,.,comma,%2C {;keys* } -\>
;semi=%3B;dot=.;comma=%2C {?list} -\> ?list=red,green,blue {?list*} -\>
?list=red\&list=green\&list=blue {?keys} -\> ?keys=semi,%3B,dot,.,comma,%2C {?keys* } -\>
?semi=%3B\&dot=.\&comma=%2C {\&list} -\> \&list=red,green,blue {\&list*} -\>
\&list=red\&list=green\&list=blue {\&keys} -\> \&keys=semi,%3B,dot,.,comma,%2C {\&keys*} -\>
\&semi=%3B\&dot=.\&comma=%2C {?var,list} -\> ?var=value\&list=red,green,blue

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> UriTemplate

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### expand(String pathUri, Object parameters, boolean addUnusedParamsAsQueryParams)

    public static String expand(String pathUri, Object parameters, boolean addUnusedParamsAsQueryParams)

Expands templates in a URI.

Supports Level 1 templates and all Level 4 composite templates as described in: [RFC 6570](http://tools.ietf.org/html/rfc6570).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `pathUri` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` URI component. It may contain one or more sequences of the form "{name}", where "name" must be a key in variableMap |
| `parameters` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` an object with parameters designated by Key annotations. If the template has no variable references, parameters may be `null`. |
| `addUnusedParamsAsQueryParams` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` If true then parameters that do not match the template are appended to the expanded template as query parameters. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | The expanded template |

### expand(String baseUrl, String uriTemplate, Object parameters, boolean addUnusedParamsAsQueryParams)

    public static String expand(String baseUrl, String uriTemplate, Object parameters, boolean addUnusedParamsAsQueryParams)

Expands templates in a URI template that is relative to a base URL.

If the URI template starts with a "/" the raw path from the base URL is stripped out. If the
URI template is a full URL then it is used instead of the base URL.

Supports Level 1 templates and all Level 4 composite templates as described in: [RFC 6570](http://tools.ietf.org/html/rfc6570).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `baseUrl` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The base URL which the URI component is relative to. |
| `uriTemplate` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` URI component. It may contain one or more sequences of the form "{name}", where "name" must be a key in variableMap. |
| `parameters` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` an object with parameters designated by Key annotations. If the template has no variable references, parameters may be `null`. |
| `addUnusedParamsAsQueryParams` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` If true then parameters that do not match the template are appended to the expanded template as query parameters. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | The expanded template |

## Constructors

### UriTemplate()

    public UriTemplate()