HttpUrl
Parsing and building HTTP/HTTPS URLs in Rust.
Features
- Fluent HTTP/HTTPS URL builder
- RFC 3986–compliant URL parsing
no_stdsupport
Quick Start
[]
= "0.1"
use ;
// Parse
let url = parse.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Build
let url = builder
.scheme
.host
.add_path_segment
.add_path_segment
.add_query_parameter
.build
.unwrap;
assert_eq!;
Builder API
builder
.scheme // Scheme::Http | Scheme::Https
.username // optional
.password // optional
.host // domain, IPv4, or [IPv6]
.port // optional, uses scheme default
.add_path_segment // decoded segment (auto-encoded)
.add_path_segment
.add_path_segments // multiple segments at once
.set_path // replace entire path (decoded)
.set_encoded_path // replace with pre-encoded path
.add_query_parameter // decoded form
.add_encoded_query_parameter // pre-encoded
.remove_query_parameter // remove all with this name
.clear_query_parameters // remove all
.fragment // decoded fragment
.encoded_fragment // pre-encoded
.remove_fragment // clear fragment
.build
.unwrap;
Query Parameters
let url = parse.unwrap;
// First value
assert_eq!;
// All values
assert_eq!;
// Missing name
assert_eq!;
// Unique names
let names = url.query_parameter_names;
assert_eq!;
assert!;
assert!;
// Count
assert_eq!;
Relative URL Resolution
let base = parse.unwrap;
// Absolute URL
assert_eq!;
// Protocol-relative
assert_eq!;
// Absolute path
assert_eq!;
// Relative path
assert_eq!;
assert_eq!;
// Query-only
assert_eq!;
// Fragment-only
assert_eq!;
url Crate Interop
Enable the optional url feature:
[]
= { = "0.1", = ["url"] }
use TryFrom;
use HttpUrl;
use Url;
// url::Url → HttpUrl (fallible, only http/https)
let u = parse.unwrap;
let http_url = try_from.unwrap;
assert_eq!;
// HttpUrl → url::Url (infallible)
let url: Url = http_url.into;
assert_eq!;
Feature Flags
| Feature | Default | Description |
|---|---|---|
std |
✅ | Enables std::error::Error impl via thiserror |
url |
❌ | Enables From/TryFrom conversions with the url crate |
no_std
The crate works without std:
[]
= { = "0.1", = false }
Only the alloc crate is required.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.