Crates.io | url-constructor |
lib.rs | url-constructor |
version | 0.1.0 |
source | src |
created_at | 2023-05-16 17:14:58.526333 |
updated_at | 2023-05-16 17:14:58.526333 |
description | Simple URL builder |
homepage | |
repository | https://github.com/ryanYtan/url-constructor |
max_upload_size | |
id | 866231 |
size | 24,207 |
A simple URL constructor with a bit more customizability.
If you do use this library, note that it does not do any error handling nor sanitation of inputs. Do verify the inputs before passing them to the builder (and experiment with the output).
In Cargo.toml
:
[dependencies]
url-constructor = "0.1.0"
To create a URL:
use url_constructor::UrlConstructor;
let url = UrlConstructor::new()
.scheme("http")
.userinfo("alex:password1")
.subdomain("api")
.host("google.com")
.port(8080)
.subdir("v2")
.subdir("users")
.param("salary", ">10000")
.param("lastName", "Wallace")
.fragment("id")
.build()
assert_eq!(
url,
"http://alex:password1@api.google.com:8080/v2/users?lastName=Wallace&salary=>10000#id"
)
These are the current "quirks" of the constructor
https
, there are no defaults for the other components://
part of the URL will not be returned&
, ?
, /
, #
and @
are automatically added to their respectively URL components (note: no checks are made to prevent duplicates)subdomain
method should yield the same result as using host
directly