#url #short #shortener #link

urlshortener

A very simple url shortener client library

20 releases (3 major breaking)

✓ Uses Rust 2018 edition

3.0.0 Mar 1, 2020
2.1.1 Feb 16, 2020
2.1.0 Dec 13, 2019
2.0.0 Aug 6, 2019
0.4.0 Jul 10, 2016

#23 in Web programming

Download history 338/week @ 2019-12-02 255/week @ 2019-12-09 109/week @ 2019-12-16 216/week @ 2019-12-23 224/week @ 2019-12-30 177/week @ 2020-01-06 163/week @ 2020-01-13 144/week @ 2020-01-20 114/week @ 2020-01-27 101/week @ 2020-02-03 216/week @ 2020-02-10 148/week @ 2020-02-17 168/week @ 2020-02-24 130/week @ 2020-03-02 152/week @ 2020-03-09 170/week @ 2020-03-16

786 downloads per month
Used in 3 crates

MIT license

29KB
512 lines

urlshortener-rs

MIT licensed

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.

Implementations

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

Usage without "client" feature

You can make a Request object without "client" feature only via provider functions:

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);
}

Usage with "client" feature

Without authentication

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));
}

With authentication (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() }));
}

Combined (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.org";
    println!("Short url for google: {:?}", us.try_generate(long_url, Some(providers)));
}

License

This project is licensed under the MIT license.

Dependencies

~1.3–4MB
~106K SLoC