Skip to content

Pass body json as a variable that can be used in the request body #1922

Open
@serle

Description

@serle

Problem to solve

Driving hurl from a test runner I need to pass a json request body variable into the hurl script. I wrap the value in single quotes so as not to break the command string, but there is no native way to tell hurl that the variable is of type json and to be able to use that json in the request body.

At the moment the workaround is to write:

my-test.hurl
GET ...
content-type: application/json

{{ body }}

Proposal

A. Allow one to type variables more explicitly

  1. add types into the option name e.g instead of --variable we could have --variable-json, --variable-int, ..
  2. add the ability to specify a conversion function within template replacement sites e.g. {{ to_json(variable) }}

B. Use above typing to infer content type for the request body so there does not need to be any workaround in the hurl file e.g. give that the variable is of type json then the above hurlfile could just be:

Option A:
hurl --test my-test.hurl --variable-json body='{ "name": "xxx" }'

my-test.hurl
GET ...
{{ body }}

Option B
hurl --test my-test.hurl --variable body='{ "name": "xxx" }'

my-test.hurl
GET ...
{{ to_json(body) }}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions