Rust-URL-Shortening

Rust URL Shortener Service

Rust Version PostgreSQL MySQL SQLite License: MIT

A full‑stack URL shortening service built entirely in Rust using Actix‑web and Diesel with SQLite. This service allows users to:


Why Use Rust?


Technology Stack


File Structure

rust-url-shortener/
├── Cargo.toml
├── .env
├── migrations/
│   └── 20230310123456_create_urls/
│       ├── up.sql
│       └── down.sql
├── src/
│   ├── main.rs
│   ├── db.rs
│   ├── models.rs
│   ├── schema.rs
│   └── routes.rs
└── README.md

Getting Started

Prerequisites

Setup

  1. Clone the Repository or Create the Project Folder

    You can create the file structure using the following terminal commands:

    # Create project directory and initialize a new binary project
    mkdir rust-url-shortener
    cd rust-url-shortener
    cargo init --bin
    
    # Create directories for Diesel migrations
    mkdir -p migrations/20230310123456_create_urls
    
    # Create migration SQL files
    touch migrations/20230310123456_create_urls/up.sql
    touch migrations/20230310123456_create_urls/down.sql
    
    # Create additional source files
    cd src
    touch db.rs models.rs schema.rs routes.rs
    cd ..
    
  2. Create a .env File

    In the project root, create a file named .env with the following content (adjust values as needed):

    DATABASE_URL=rust_url_shortener.db
    BASE_URL=http://localhost:8080
    
  3. Run Diesel Migrations

    Set up the database schema by running:

    diesel migration run
    

Running the Application

  1. Build and Run the Server

    cargo run
    

    The server will start at http://localhost:8080.

  2. API Endpoints


Customization


Contributing

Feel free to fork this repository and submit pull requests with improvements or customizations. For issues or feature requests, please open an issue.


License

This project is licensed under the MIT License.


Authors

The UNC-CH Google Developer Student Club (GDSC) team.