diff --git a/docs/pages/keyconcepts/templating/templating.rst b/docs/pages/keyconcepts/templating/templating.rst index 496e62586..e79e96535 100644 --- a/docs/pages/keyconcepts/templating/templating.rst +++ b/docs/pages/keyconcepts/templating/templating.rst @@ -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' }} | 123 | 123 | -+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ -| From data | {{ Request.FormData.email }} | email=foo@bar.com | foo@bar.com | -+------------------------------+----------------------------------------------+----------------------------------------------+----------------+ -| 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' }}`` | 123 | 123 | ++------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ +| From data | ``{{ Request.FormData.email }}`` | email=foo@bar.com | foo@bar.com | ++------------------------------+-------------------------------------------------+----------------------------------------------+----------------+ +| 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 }} | LoriStewart@Photolist.com | +| A random email address | ``{{ randomEmail }}`` | LoriStewart@Photolist.com | +-----------------------------------------------------------+-----------------------------------------------------------+-----------------------------------------+ -| 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