hurl icon indicating copy to clipboard operation
hurl copied to clipboard

Support using filters to construct request body

Open skeggse opened this issue 8 months ago • 2 comments

Problem to solve

I'm testing AWS endpoints (actually AWS Lambda functions), which sometimes desire JSON requests with an embedded base64 payload. Just writing out the request this way means that the .hurl file has some JSON with a big base64 blob in the middle, which isn't particularly easy to read.

Proposal

Since there's already filter support for base64Encode, it'd be great if I could use variable support in [Options] to encode my base64 and then embed it in the JSON as a template:

[Options]
variable: base64_data="test" base64Encode
```json
{
  "records": [
    {
      "message": {{base64_data}}
    }
  ]
}
```

to produce a request body of

{"records":[{"message":"dGVzdA=="}]}

Additional context and resources

Tasks to complete

  • [ ] ...

skeggse avatar Apr 25 '25 20:04 skeggse

Ah I think this will be the generators feature mentioned by @jcamiel in https://github.com/Orange-OpenSource/hurl/issues/2258#issuecomment-1861512751.

skeggse avatar May 01 '25 17:05 skeggse

Yes, we plan to be use more complex expression in template, variable etc like:

POST https://foo.com
{
  "records": [
    {
      "message": {{ my_var base64Encode }}
    }
  ]
}

Generators (we call it function now) are part of these evolutions and allow to produce data like date or uuid:

POST https://foo.com
{
  "records": [
    {
      "message": {{ newUuid }}
    }
  ]
}

And we'll be able to combine functions with filters:

POST https://foo.com
{
  "records": [
    {
      "message": {{ newUuid base64UrlDecode }}
    }
  ]
}

I'm not sure of the roadmap but this is the plan we're committing on.

jcamiel avatar May 01 '25 18:05 jcamiel