hurl
hurl copied to clipboard
[Captures] and [Asserts]: add support for query parameters parsing
Problem to solve
Maybe this is a very specific use-case, so I don't know if it's very useful and worth a feature implementation, (and maybe there is a macro for this and I ignored it - first times using hurl :) ), but in one of my hurls I had the need to parse query parameters that were specified in a JSON returned body field, in order to use them in a subsequent request. Specifically, returned body:
{
...
"url": "https://domain.net?param1=foo¶m2=bar"
...
}
To parse param1 and param2 and use those in a subsequent request, I used the regex macro in my [Captures] section:
[Captures]
param1: jsonpath "$.url" regex "param1=(.*)" split "&" nth 0
param2: jsonpath "$.url" regex "param2=(.*)"
Which works, but is a bit tricky.
Proposal
Add a specific API for parsing query params in [Captures] and [Asserts] sections. Something in the like:
[Captures]
param1: jsonpath "$.url" queryparam "param1"
Tasks to complete
- [ ] Support query parameters parsing
Hi @Muntaner,
This seems indeed quite specific.
But at the same time, it's nice to be able to process url easily.
It could be reused for example to extract parameters from a redirect (Location
header).
I would say why not.