25 个版本 (11 个稳定版)
| 3.2.1 | 2024 年 5 月 14 日 |
|---|---|
| 3.2.0 | 2024 年 3 月 9 日 |
| 3.1.0 | 2023 年 12 月 17 日 |
| 3.0.2 | 2022 年 11 月 20 日 |
| 0.4.0 | 2016 年 7 月 10 日 |
在 Web 编程 中排名第 589
每月下载 128 次
在 4 crates 中使用
31KB
538 行
urlshortener-rs
Rust 的一个非常简单的 URL 缩短程序。
此库旨在尽可能实现 URL 缩短服务,并提供尽可能简单和最少的接口。为了减轻依赖问题,从 0.9.0 版本开始,库提供了请求对象,可用于通过用户 http-client 库执行请求。
MSRV
由于依赖项之一,最低支持的 Rust 版本已提升至 1.63。代码本身应与 Rust 版本 1.46 兼容,甚至可能是更低版本。
实现
目前实现了以下 URL 缩短程序
带有身份验证
goo.glbit.lykutt.it(支持自托管)
未带身份验证
bn.gyis.gdv.gdbam.bzfifo.cctiny.phtny.ims.coopbmeo.orghmm.rsurl-shortener.iobiturl.top
以下服务受支持,但由于速率限制等限制而不鼓励使用
tinyurl.compsbe.corlu.rusirbz.comhec.suabv8.menowlinks.net
没有 "client" 功能的用法 无
您可以通过提供函数仅通过 "client" 功能创建一个 Request 对象
extern crate urlshortener;
use urlshortener::providers::{Provider, self};
fn main() {
let long_url = "https://google.com";
let key = "MY_API_KEY";
let req = providers::request(long_url, &Provider::GooGl { api_key: key.to_owned() });
println!("A request object for shortening URL via GooGl: {:?}", req);
}
使用 "client" 功能的用法
未带身份验证
extern crate urlshortener;
use urlshortener::client::UrlShortener;
fn main() {
let us = UrlShortener::new().unwrap();
let long_url = "https://google.com";
println!("Short url for google: {:?}", us.try_generate(long_url, None));
}
带有身份验证 (Goo.Gl)
extern crate urlshortener;
use urlshortener::{ client::UrlShortener, providers::Provider };
fn main() {
let us = UrlShortener::new().unwrap();
let long_url = "https://google.com";
let key = "MY_API_KEY";
println!("Short url for google: {:?}", us.generate(long_url, Provider::GooGl { api_key: key.to_owned() }));
}
组合 (Goo.Gl + Is.Gd)
extern crate urlshortener;
use urlshortener::{ client::UrlShortener, providers::Provider };
fn main() {
let us = UrlShortener::new().unwrap();
let providers = vec![
Provider::GooGl { api_key: "MY_API_KEY".to_owned() },
Provider::IsGd,
];
let long_url = "https://rust-lang.net.cn";
println!("Short url for google: {:?}", us.try_generate(long_url, Some(providers)));
}
许可证
此项目受 MIT 许可证 许可。
依赖项
~1–11MB
~141K SLoC