Skip to content

WilfredAlmeida/rusly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rusly: URL Shortener built using Rust

Check out Rusly

Rusly is built using the Rocket framework

Check out the system design of Rusly here

Check out Rusly's simple HTML, CSS UI repo

API Endpoints

Let's take a quick look at the available endpoints

Route Description Request Body Response
/ GET The default home route None Hello Heckerr
/v1/shorten POST Takes in the URL to shorten and returns the shortened URL. - url_to_shorten: String url to shorten - shortened_url: A shortened string URL.
- custom_link: Optional, strictly 7-character alphabetic custom shortened URL string - error: Error message string
/<short-url GET Permanently redirects to the specified short URL string None None

Database

Currently, the SQLite database is used as an embedded database.

Database Schema

id

VARCHAR(7) PRIMARY KEY

fullUrl

VARCHAR(1024) NOT NULL

timestamp

INTEGER NOT NULL

Schema Description

id: The randomly generated string acts as the shortened URL string. This being a primary key ensures that there are no duplicate short URLs.

In the case of custom short URLs, it won't be allowed either.

Since the length of the short URL is 7 characters, there are over 8 billion possible combinations that are sufficient and uniqueness is maintained by the primary key.

fullUrl: The full URL string. Is fetched and the user is redirected permanently.

timestamp: The UNIX timestamp of entry. It is provided in the Rust code in the insert query. The commit time of the record and this timestamp may vary.


Concurrency

Rocket is multi-threaded by default, it spins up worker threads and divides the workload. More details here

Database Concurrency

Rocket provides database pools for providing database connection objects via state

It provides a rusqlite connection out of the box, with additional benefits of thread safety, and connection pooling.


Running Locally

  1. Install Rust
    You might need a specific version for Rocket, check the docs once.

  2. Clone this repo

  3. Run cargo run
    It'll take some and Rusly will be up & running on 127.0.0.1:8001

My Versions

Following are the versions I used

rustc 1.68.2
cargo 1.68.2

Contributing

Please refer to the CONTRIBUTING.md file and the open issues for any contribution and communication.

Get in touch with me

About

A URL Shortener built using Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages