A very simple urlshortener for Rust.
This library aims to implement as much URL shortener services as possible and to provide an interface as minimal and simple as possible. For easing pain with dependency hell, the library provides request objects since 0.9.0 version which can be used for performing requests via user http-client library.
The minimum supported rust version is bumped to 1.56 just because one of the dependencies. The code itself should work fine with Rust version 1.46, and, perhaps, even lower versions.
Currently the following URL shorteners are implemented:
With authentication:
goo.gl
bit.ly
kutt.it
(supports self hosting)Without authentication:
bn.gy
is.gd
v.gd
bam.bz
fifo.cc
tiny.ph
tny.im
s.coop
bmeo.org
hmm.rs
url-shortener.io
The following services are supported, but are discouraged from use, due to restrictions such as rate limits:
tinyurl.com
psbe.co
rlu.ru
sirbz.com
hec.su
abv8.me
nowlinks.net
You can make a Request
object without "client" feature only via provider functions:
```rust extern crate urlshortener;
use urlshortener::providers::{Provider, self};
fn main() { let longurl = "https://google.com"; let key = "MYAPIKEY"; let req = providers::request(longurl, &Provider::GooGl { apikey: key.toowned() }); println!("A request object for shortening URL via GooGl: {:?}", req); } ```
Without authentication
```rust extern crate urlshortener;
use urlshortener::client::UrlShortener;
fn main() { let us = UrlShortener::new().unwrap(); let longurl = "https://google.com"; println!("Short url for google: {:?}", us.trygenerate(long_url, None)); } ```
With authentication (Goo.Gl)
```rust extern crate urlshortener;
use urlshortener::{ client::UrlShortener, providers::Provider };
fn main() { let us = UrlShortener::new().unwrap(); let longurl = "https://google.com"; let key = "MYAPIKEY"; println!("Short url for google: {:?}", us.generate(longurl, Provider::GooGl { apikey: key.toowned() })); } ```
Combined (Goo.Gl + Is.Gd)
```rust extern crate urlshortener;
use urlshortener::{ client::UrlShortener, providers::Provider };
fn main() {
let us = UrlShortener::new().unwrap();
let providers = vec![
Provider::GooGl { apikey: "MYAPIKEY".toowned() },
Provider::IsGd,
];
let longurl = "https://rust-lang.org";
println!("Short url for google: {:?}", us.trygenerate(long_url, Some(providers)));
}
```
This project is licensed under the MIT license.