Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magiclen/url-prefix
A library for creating URL prefix strings.
https://github.com/magiclen/url-prefix
rust
Last synced: 28 days ago
JSON representation
A library for creating URL prefix strings.
- Host: GitHub
- URL: https://github.com/magiclen/url-prefix
- Owner: magiclen
- License: mit
- Created: 2018-10-12T06:05:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-11T02:24:19.000Z (over 1 year ago)
- Last Synced: 2024-10-12T05:45:49.274Z (2 months ago)
- Topics: rust
- Language: Rust
- Homepage:
- Size: 25.4 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
URL Prefix
====================[![CI](https://github.com/magiclen/url-prefix/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/url-prefix/actions/workflows/ci.yml)
This crate can be used to create URL prefix strings by inputting a protocol, a domain, a port number and a path without additional parsing.
## Why We Need This?
Sometimes our web applications are run on different protocols(HTTP/HTTPS) and domains. And it is boring to write some code like below to format a URL:
```rust
let mut url_prefix = String::new();
if is_https {
url_prefix.push_str("https://");
} else {
url_prefix.push_str("http://");
}
url_prefix.push_str(domain);if is_https && port != 443 || !is_https && port != 80 {
url_prefix.push_str(":");
url_prefix.push_str(&port.to_string());
}
```Instead, we can easily use this crate to create URL prefix strings. For examples,
```rust
let prefix = url_prefix::create_prefix(url_prefix::Protocol::HTTPS, "magiclen.org", None, None);assert_eq!("https://magiclen.org", prefix);
``````rust
let prefix = url_prefix::create_prefix(url_prefix::Protocol::HTTPS, "magiclen.org", Some(8100), Some("url-prefix"));assert_eq!("https://magiclen.org:8100/url-prefix", prefix);
```## Crates.io
https://crates.io/crates/url-prefix
## Documentation
https://docs.rs/url-prefix
## License
[MIT](LICENSE)