From 0fcb38d65160f77c4e8942c6fca1f905e679950e Mon Sep 17 00:00:00 2001 From: Gurleen Sethi Date: Wed, 29 Mar 2023 00:38:30 -0400 Subject: [PATCH] docs: variable types --- docs/variables.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/variables.md b/docs/variables.md index 3fd7694..aeff2e5 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -129,4 +129,44 @@ You can provide as many variable files as you want. $ yurl -var-file local.vars -var-file staging.vars Login ``` -All the variables are added to the **variable set**. \ No newline at end of file +All the variables are added to the **variable set**. + +## Variable Types + +You can define types on variables when the value is prompted from the user. + +Use the pattern: `{{ : }}` to enforce a type. + +```yaml title="http.requests" +requests: + GetTodoById: + method: GET + path: /todos/{{ id:int }} # (1)! + headers: + Accept: application/json +``` + +1. Types are defined using `:` pattern. + +```bash linenums="0" +$ yurl GetTodoById +Enter `id` (int): 10 +``` + +In the above example, type `int` is defined for the variable `id`. When the prompt is presented to the user for value the required type is also displayed. + +If the entered value is not valid, `yurl` errors immediately. + +```bash linenums="0" +$ yurl GetTodoById +Enter `id` (int): not int + +input for `id` must be of type int +``` + +Currently the following types are supported: + +- `string` +- `int` +- `float` +- `bool`