-
Notifications
You must be signed in to change notification settings - Fork 694
Description
Problem to solve
At the moment, when i have a set of query parameters that are not required by a request (aka they are optional), i have to either change the hurl file for every request or create a hurl file for every possible combination of query parameters and headers that can be used.
For example, let's say i have an API that can be either accessed directly (e.g. when testing locally) or via some kind of API gateway. When accessing it via an API-gateway, i need to provide an access token. When accessing it locally, i need to provide a JWT token that is usually provided by the API gateway. This could be done like this (using the default X-JWT-Assertion header that is used by WSO2 APIM):
GET {{apiUrl}}/path/to/my/api/route
Authorization: {{accessToken}}
X-JWT-Assertion: {{jwtToken}}
In this case i could execute the script with hurl --variable apiUrl=http://localhost:1234 --variable jwtToken=... hurl-file.hurl locally (with ... being some kind of valid JWT) and hurl --variable apiUrl=https://api-gateway.my-domain.com --variable accessToken=... hurl-file.hurl for accessing the API via its gateway-URL.
The same goes for query parameters. Let's say i have an API route for searching for items with a number of query parameters defining what to search for, e.g. filename, containsText, id:
GET {{apiUrl}}/path/to/my/api/search
[Query]
filename={{filename}}
containsText={{containsText}}
id={{id}}
Right now, all those variables need to be defined and all query parameters will be set in the request. But i would be nice to be able to choose not to provide e.g. the containsText variable, effectively removing the containsText query parameter from the request.
This is different to setting the query parameter to an empty value with --variable containsText= because in the latter case the query parameter is still sent in the request, meaning in the API it will usually be received as an empty string "" which is not the same as null / undefined.
Proposal
I propose a way to make variables optional, meaning if they are not provided and a request parameter (header, query) depends on that variable, that dependent request parameter will also not be provided in the request.
Probably the easiest way to do this would be an additional command line parameter --variable-unset variableName which tells hurl to explicitly unset the variable (or define it as null / undefined / None). Then when the request is built, all query parameters and headers that have such an unset variable as their only content should be ignored.
Alternatively some syntax could be introduced for making the variable value optional, e.g. {{ variableName? }}, which means no error will be shown if the variable is not provided.