Visitar URL original
Library mode · Issue #4818 · Orange-OpenSource/hurl · GitHub
Skip to content

Library mode #4818

Open
Open

Description

@gtrak

Problem to solve

We came upon this tool to help with user-facing test harnesses over our services.

Before hurl, I was essentially scripting http calls with regular rust and wanted a way to emit the equivalent curl commands for documentation purposes. I see the value of hurl, but it can't be used inside rust code as far as I can tell.

Proposal

Library-mode

I've seen a templating approach for SQL queries that might work here and give the best of both worlds. The idea is that real code would use the templates you already to make its own requests, so you have an http template file that can be used in regular rust code and in the current CLI-scripting use-case as well.

I think this would take some macro magic to make the programmatic API, but hurl is already doing most of what's needed.

Activity

  1. jcamiel commented on Feb 23, 2026

    @jcamiel
    Collaborator

    Hi @gtrak

    Thanks for the issue. I'm not sure to fully understand your use case, just in case you don't know it yet, Hurl is available as a standalone cli tool and as a Rust crate (a library in Rust world). You can totally build your own code / logic around the Hurl crate if the standalone CLi doesn't full fit your needs (you can make the parallel with curl / libcurl)

    A Rust sample code using the Hurl crate:

    use std::collections::HashMap;
    use hurl::runner;
    use hurl::runner::{Value, RunnerOptionsBuilder, VariableSet};
    use hurl::util::logger::{LoggerOptionsBuilder, Verbosity};
    use hurl_core::input::Input;
    
    // A simple Hurl sample
    let content = r#"
    GET http://localhost:8000/hello
    HTTP 200
    "#;
    
    let filename = Input::new("sample.hurl");
    
    // Define runner and logger options
    let runner_opts = RunnerOptionsBuilder::new()
        .follow_location(true)
        .build();
    let logger_opts = LoggerOptionsBuilder::new()
        .verbosity(Some(Verbosity::Verbose))
        .build();
    
    // Set variables
    let mut variables = VariableSet::new();
    variables.insert("name".to_string(), Value::String("toto".to_string()));
    
    // Run the Hurl sample
    let result = runner::run(
        content,
        Some(filename).as_ref(),
        &runner_opts,
        &variables,
        &logger_opts
    );
    assert!(result.unwrap().success);

    More info here => https://docs.rs/hurl/latest/hurl/runner/fn.run.html

  2. SilenLoc commented on Feb 27, 2026

    @SilenLoc

    @gtrak please corret me but you mean something like maud for html you want to have a macro for inlining hurl files for hurl and then running the output of that?

  3. gtrak commented on Feb 27, 2026

    @gtrak
    Author

    That looks cool! But, it's a different thing. The reply from @jcamiel is mostly what I was thinking about, except a macro could make it more typesafe with slots for specific query params, a-la https://github.com/kysely-org/kysely . I guess Maud is similar? But, the templates would stay in separate files so I could still run them with hurl CLI.

  4. SilenLoc commented on Mar 2, 2026

    @SilenLoc

    @gtrak Thanks for trying to clarify, but I am still not sure what you mean tbh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions