feat(hurl): Implement Hurl file importer for macOS #918
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Description
Overview
This pull request implements functional Hurl file import capability for API Dash on macOS, building upon the foundational Flutter Rust Bridge infrastructure established by @WrathOP. Support for other platforms remains a known issue (detailed below), but this provides the foundation.
The implementation utilizes the official
hurl_corev7.0.0 Rust library through FFI, following the architectural direction suggested by @ashitaprasad to leverage Flutter Rust Bridge for generating Dart-readable JSON output from Hurl files.Technical Approach and Key Differences
The current solution utilizes
hurl_core::parser::parse_hurl_file()and manually extracts only the HTTP request-relevant data from the AST, producing a simplified JSON structure tailored for API Dash's data models.This approach addresses the core requirement identified by @ashitaprasad: using Flutter Rust Bridge to parse Hurl files into Dart-readable JSON format, rather than attempting to reimplement the Hurl specification in pure Dart.
Implementation Details
The implementation follows a three-layers:
Rust FFI Bridge (hurl_parser.rs): The Rust layer exposes a single function parse_hurl_to_json(). It uses the official hurl_core library to parse the .hurl file, traverse its AST, and extract relevant request fields (method, URL, headers, bodies, auth, etc.) into a simplified JSON string.
Dart Integration (hurl_io.dart): The HurlIO class consumes this JSON and maps it to API Dash's HttpRequestModel. This layer handles the "business logic" of converting Hurl-specific sections (like [BasicAuth] and [Cookies]) into the standard HTTP headers and models that Apidash understands.
Build System Integration (Cargokit): Cargokit manages the Rust compilation and links the resulting dynamic library into the Flutter app during the build process.
Feature Coverage and Hurl Specification Support
The implementation supports the following Hurl features with varying degrees of completeness:
HTTPVerbenumurl+paramsheaderslist[QueryStringParams]Sectionparams[FormParams]SectionformDatawithContentType.formdata[MultipartFormData]SectionformDatawith type metadata[BasicAuth]SectionAuthorizationheader[Cookies]SectionCookieheaderbodywithContentType.jsonbodywithContentType.text[Options]SectionCritical Limitations and Platform Constraints
FFI Testing Architecture Constraints
The test suite in
hurl_parser_test.dartcannot execute via the standardflutter testcommand due to fundamental FFI architectural limitations. The Dart VM test environment does not include the compiled Rust dynamic library, which is only built during full application compilation throughflutter buildorflutter run. This constraint affects all Flutter FFI implementations and is not specific to this codebase.Platform-Specific Build Requirements: macOS
On macOS, the Hurl Rust library has a transitive dependency on
libxml2for XML parsing capabilities. While macOS includes a systemlibxml2, the Homebrew-installed version is often required for proper compilation. The Podfile requires manual modification after runningflutter create --platforms=macos .to add necessary linker flags:This limitation is inherited from @WrathOP's original implementation. Since the macos directory is Flutter-generated and conventionally excluded from version control, developers must manually apply these modifications. This represents a known documentation gap and a significant friction point for other contributors.
@ashitaprasad - I'm not familiar enough with Cargokit or the Podfile to automate this. Do you have any suggestions on how we could script these linker flags as part of the flutter build process?
Cross-Platform Testing Status and Known Blockers
Testing has been conducted exclusively on macOS (Apple Silicon M-series processor) because that is the machine I own. The implementation theoretically supports all platforms through Cargokit's cross-compilation infrastructure, but the following platforms remain unverified:
Windows: Cargokit should compile successfully on Windows, but Windows-specific linker requirements and
libxml2availability are unknown. The Rust ecosystem supports Windows natively, suggesting likely compatibility, but verification is required.Linux: Expected to work without significant modification, as Linux distributions typically include
libxml2development packages. The dynamic library linking process on Linux may require different configuration than macOS, pending verification.iOS and Android: These platforms face a critical blocker identified by @WrathOP during initial implementation. Mobile platforms do not include
libxml2as a system library, and the Rust crate wrapper used byhurl_coredoes not currently support iOS or Android compilation targets. @WrathOP's extensive investigation documented influtter_rust_bridge_experiment.mddetails the attempted solutions and confirmed this as an unresolved issue.The mobile platform limitation represents the primary outstanding technical challenge for this feature. Potential solutions documented by @WrathOP include using legacy Hurl versions predating the
libxml2dependency, implementing custom XML parsing, or waiting for mobile platform support in the Rustlibxml2wrapper crate. Each approach involves significant trade-offs in terms of maintenance burden, feature completeness, and implementation complexity.Demonstration Video
hurl-implementation.mp4
Related Issues
Checklist
mainbranch before making this PRflutter upgradeand verify)flutter test) and all tests are passingAdded/updated tests?
OS on which you have developed and tested the feature?
Platform Testing Notes:
Development and comprehensive testing were conducted exclusively on macOS running on Apple Silicon (M-series) processors. The implementation utilizes Cargokit for theoretical cross-platform support, but other platforms remain untested in this PR.