hurl icon indicating copy to clipboard operation
hurl copied to clipboard

How to run a single request from a file

Open kai687 opened this issue 2 years ago • 6 comments

Problem to solve

How to run a single request from a file that has many? For example, I have 4 requests in one file, but I only want to run the 3rd one?

As far as I understood, the --to-entry flag runs all requests in a file up to an entry number.

Proposal

Could there be an accompanying command-line option for running a single request in a file?

Additional context and resources

Tasks to complete

  • [ ] ...

kai687 avatar Dec 14 '23 16:12 kai687

Hi @kai687, we could naturally add --from--entry option, and maybe also --entry

fabricereix avatar Dec 14 '23 16:12 fabricereix

When using --to-entry, I find myself wanting to have the option --to-line: it easier to view a request line in an editor than to count the corresponding entry number (see #1820). In the same vein, we could add --line to execute a particular request at at particular line number.

jcamiel avatar Dec 14 '23 17:12 jcamiel

@jcamiel Since a request entry can span multiple lines, what if that line is a comment? Or part of an Asserts block?

kai687 avatar Dec 14 '23 18:12 kai687

Yes exactly we've to defined this!

I'll be happy with --to-line executing the request on the exact line or the last request before this line. We could even return an error if there is no request at the specified line. Both behavior will be better than counting the request in the file to know what is the entry of the request I want to execute (which I'm doing every time I use --to-entry)

jcamiel avatar Dec 14 '23 19:12 jcamiel

@fabricereix I would like to see multi request single file support similar to the http vscode extension

This is an example of what the file format from the extension supports:

@hostname = api.example.com
@port = 8080
@host = {{hostname}}:{{port}}
@contentType = application/json
@createdAt = {{$datetime iso8601}}
@modifiedBy = {{$processEnv USERNAME}}

###
@name = hello
GET https://{{host}}/authors/{{name}} HTTP/1.1

You can define variables on a top level without coupling to a request and each request can have it's own custom @name identifier.

With this feature, Hurl can run a single request based on a @name value the user provides

lkuoch avatar Dec 21 '23 03:12 lkuoch

Yes, relating to your @name attribute, we plan to add metadata for each request (#1949)

fabricereix avatar Dec 21 '23 09:12 fabricereix

With Hurl 4.3.0, we've introduced --from-entry option. Combined with --to-entry the two options can be used to execute a particular entry.

jcamiel avatar Apr 29 '24 17:04 jcamiel