| Crates.io | httprunner-lib |
| lib.rs | httprunner-lib |
| version | 0.6.45 |
| created_at | 2026-01-18 00:41:52.296398+00 |
| updated_at | 2026-01-18 10:45:34.214357+00 |
| description | HTTP File Runner - Core library for executing HTTP requests from .http files |
| homepage | https://github.com/christianhelle/httprunner |
| repository | https://github.com/christianhelle/httprunner |
| max_upload_size | |
| id | 2051506 |
| size | 424,029 |
A powerful Rust library for parsing and executing HTTP requests from .http files. This is the core library that powers the httprunner CLI tool.
httprunner-lib provides a complete solution for working with .http files - a simple text-based format for defining HTTP requests. It handles parsing, variable substitution, request execution, and response validation.
.http filesguid(), string(), number(), base64_encode())@dependsOn and @if directives.http file discoveryAdd this to your Cargo.toml:
[dependencies]
httprunner-lib = "0.1.0"
use httprunner_lib::{parser::parse_http_file, runner::execute_http_request};
fn main() -> anyhow::Result<()> {
// Parse an .http file
let requests = parse_http_file("example.http", None)?;
// Execute the first request
if let Some(request) = requests.first() {
let result = execute_http_request(request, false, false)?;
println!("Status: {}", result.status_code);
println!("Body: {}", result.body);
}
Ok(())
}
use httprunner_lib::processor::process_http_files;
fn main() -> anyhow::Result<()> {
// Process one or more .http files
let files = vec!["example.http".to_string()];
let results = process_http_files(
&files,
false, // verbose
None, // log_filename
None, // environment
false, // insecure
false, // pretty_json
)?;
// Calculate totals from file results
let total_success: u32 = results.files.iter().map(|f| f.success_count).sum();
let total_failed: u32 = results.files.iter().map(|f| f.failed_count).sum();
let total_skipped: u32 = results.files.iter().map(|f| f.skipped_count).sum();
println!("Success: {}, Failed: {}, Skipped: {}", total_success, total_failed, total_skipped);
Ok(())
}
The library supports a simple, intuitive format for defining HTTP requests:
# Basic GET request
GET https://api.github.com/users/octocat
###
# POST request with headers and body
POST https://httpbin.org/post
Content-Type: application/json
{
"name": "test",
"value": 123
}
Variables make your .http files reusable across different environments:
@hostname=localhost
@port=8080
GET https://{{hostname}}:{{port}}/api/users
Authorization: Bearer {{token}}
Chain requests by extracting data from previous responses:
# @name login
POST https://api.example.com/login
Content-Type: application/json
{
"username": "admin",
"password": "secret"
}
###
# Use the token from the login response
# @name get_data
GET https://api.example.com/data
Authorization: Bearer {{login.response.body.$.token}}
Validate responses with built-in assertions:
GET https://api.example.com/users/1
EXPECTED_RESPONSE_STATUS 200
EXPECTED_RESPONSE_BODY "John Doe"
EXPECTED_RESPONSE_HEADERS "Content-Type: application/json"
Execute requests conditionally based on previous results:
# @name check-user
GET https://api.example.com/user/123
###
# Create only if user doesn't exist
# @if check-user.response.status 404
POST https://api.example.com/user
Content-Type: application/json
{
"id": 123,
"name": "New User"
}
Generate dynamic values with built-in functions:
POST https://api.example.com/users
Content-Type: application/json
{
"id": "guid()",
"sessionKey": "string()",
"randomValue": "number()",
"credentials": "base64_encode('username:password')"
}
Support different environments with http-client.env.json:
{
"dev": {
"HostAddress": "https://localhost:44320",
"ApiKey": "dev-api-key-123"
},
"prod": {
"HostAddress": "https://contoso.com",
"ApiKey": "prod-api-key-789"
}
}
Then reference variables in your .http files:
GET {{HostAddress}}/api/data
Authorization: Bearer {{ApiKey}}
.http files as executable documentationFor comprehensive documentation, examples, and advanced features, see the main repository.
This project is licensed under the MIT License - see the LICENSE file for details.
cargo install httprunner