-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formatted all templating examples as code (#1059)
Because otherwise readthedocs renders them with fancy quotes {{ now ‘1d’ ‘unix’ }}
- Loading branch information
Showing
1 changed file
with
41 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,31 +18,31 @@ Getting data from the request | |
|
||
Currently, you can get the following data from request to the response via templating: | ||
|
||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Field | Example | Request | Result | | ||
+==============================+==============================================+==============================================+================+ | ||
| Request scheme | {{ Request.Scheme }} | http://www.foo.com | http | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Query parameter value | {{ Request.QueryParam.myParam }} | http://www.foo.com?myParam=bar | bar | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Query parameter value (list) | {{ Request.QueryParam.NameOfParameter.[1] }} | http://www.foo.com?myParam=bar1&myParam=bar2 | bar2 | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Path parameter value | {{ Request.Path.[1] }} | http://www.foo.com/zero/one/two | one | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Method | {{ Request.Method }} | http://www.foo.com/zero/one/two | GET | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| jsonpath on body | {{ Request.Body 'jsonpath' '$.id' }} | { "id": 123, "username": "hoverfly" } | 123 | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| xpath on body | {{ Request.Body 'xpath' '/root/id' }} | <root><id>123</id></root> | 123 | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| From data | {{ Request.FormData.email }} | [email protected] | [email protected] | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Header value | {{ Request.Header.X-Header-Id }} | { "X-Header-Id": ["bar"] } | bar | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| Header value (list) | {{ Request.Header.X-Header-Id.[1] }} | { "X-Header-Id": ["bar1", "bar2"] } | bar2 | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
| State | {{ State.basket }} | State Store = {"basket":"eggs"} | eggs | | ||
+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Field | Example | Request | Result | | ||
+==============================+=================================================+==============================================+================+ | ||
| Request scheme | ``{{ Request.Scheme }}`` | http://www.foo.com | http | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Query parameter value | ``{{ Request.QueryParam.myParam }}`` | http://www.foo.com?myParam=bar | bar | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Query parameter value (list) | ``{{ Request.QueryParam.NameOfParameter.[1] }}``| http://www.foo.com?myParam=bar1&myParam=bar2 | bar2 | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Path parameter value | ``{{ Request.Path.[1] }}`` | http://www.foo.com/zero/one/two | one | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Method | ``{{ Request.Method }}`` | http://www.foo.com/zero/one/two | GET | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| jsonpath on body | ``{{ Request.Body 'jsonpath' '$.id' }}`` | { "id": 123, "username": "hoverfly" } | 123 | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| xpath on body | ``{{ Request.Body 'xpath' '/root/id' }}`` | <root><id>123</id></root> | 123 | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| From data | ``{{ Request.FormData.email }}`` | [email protected] | [email protected] | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Header value | ``{{ Request.Header.X-Header-Id }}`` | { "X-Header-Id": ["bar"] } | bar | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| Header value (list) | ``{{ Request.Header.X-Header-Id.[1] }}`` | { "X-Header-Id": ["bar1", "bar2"] } | bar2 | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
| State | ``{{ State.basket }}`` | State Store = {"basket":"eggs"} | eggs | | ||
+------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ | ||
|
||
Helper Methods | ||
-------------- | ||
|
@@ -56,37 +56,37 @@ Additional data can come from helper methods. These are the ones Hoverfly curren | |
| | | | | ||
| For example: | | | | ||
| | | | | ||
| - The current date time plus 1 day in unix timestamp | - {{ now '1d' 'unix' }} | - 1136300645 | | ||
| - The current date time in ISO 8601 format | - {{ now '' '' }} | - 2006-01-02T15:04:05Z | | ||
| - The current date time minus 1 day in custom format | - {{ now '-1d' '2006-Jan-02' }} | - 2006-Jan-01 | | ||
| - The current date time plus 1 day in unix timestamp | - ``{{ now '1d' 'unix' }}`` | - 1136300645 | | ||
| - The current date time in ISO 8601 format | - ``{{ now '' '' }}`` | - 2006-01-02T15:04:05Z | | ||
| - The current date time minus 1 day in custom format | - ``{{ now '-1d' '2006-Jan-02' }}`` | - 2006-Jan-01 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random string | {{ randomString }} | hGfclKjnmwcCds | | ||
| A random string | ``{{ randomString }}`` | hGfclKjnmwcCds | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random string with a specified length | {{ randomStringLength 2 }} | KC | | ||
| A random string with a specified length | ``{{ randomStringLength 2 }}`` | KC | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random boolean | {{ randomBoolean }} | true | | ||
| A random boolean | ``{{ randomBoolean }}`` | true | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random integer | {{ randomInteger }} | 42 | | ||
| A random integer | ``{{ randomInteger }}`` | 42 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random integer within a range | {{ randomIntegerRange 1 10 }} | 7 | | ||
| A random integer within a range | ``{{ randomIntegerRange 1 10 }}`` | 7 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random float | {{ randomFloat }} | 42 | | ||
| A random float | ``{{ randomFloat }}`` | 42 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random float within a range | {{ randomFloatRange 1.0 10.0 }} | 7.4563213423 | | ||
| A random float within a range | ``{{ randomFloatRange 1.0 10.0 }}`` | 7.4563213423 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random email address | {{ randomEmail }} | [email protected] | | ||
| A random email address | ``{{ randomEmail }}`` | [email protected] | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random IPv4 address | {{ randomIPv4 }} | 224.36.27.8 | | ||
| A random IPv4 address | ``{{ randomIPv4 }}`` | 224.36.27.8 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random IPv6 address | {{ randomIPv6 }} | 41d7:daa0:6e97:6fce:411e:681:f86f:e557 | | ||
| A random IPv6 address | ``{{ randomIPv6 }}`` | 41d7:daa0:6e97:6fce:411e:681:f86f:e557 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| A random UUID | {{ randomUuid }} | 7b791f3d-d7f4-4635-8ea1-99568d821562 | | ||
| A random UUID | ``{{ randomUuid }}`` | 7b791f3d-d7f4-4635-8ea1-99568d821562 | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| Replace all occurrences of the old value with the new | {{ replace Request.Body 'be' 'mock' }} | | | ||
| Replace all occurrences of the old value with the new | ``{{ replace Request.Body 'be' 'mock' }}`` | | | ||
| | | | | ||
| value in the target string | (where Request.Body has the value of "to be or not to be" | to mock or not to mock | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
| Generate random data using go-fakeit | {{ faker 'Name' }} | John Smith | | ||
| Generate random data using go-fakeit | ``{{ faker 'Name' }}`` | John Smith | | ||
+-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ | ||
|
||
Time offset | ||
|