Giter Club home page Giter Club logo

rs-short's Introduction

rs-short - A Simple URL Shortener in Rust

rs-short is a lightweight URL shortener built with Warp and SQLx.

Features

  • Shorten URLs with a simple POST request.
  • Retrieve and redirect to the original URL with the shortened path.
  • Tracks the number of times each shortened URL is accessed.
  • (Optional) Assign a user to a shortened URL.

Setup

Prerequisites

  1. Rust (latest stable version)
  2. PostgreSQL Database

Configuration

  1. Setup your PostgreSQL database and create the urls table:
CREATE TABLE urls (
    key TEXT PRIMARY KEY,
    value TEXT NOT NULL,
    user_id TEXT,
    visit_count INTEGER DEFAULT 0
);
  1. Set your database URL in an environment variable:
export DATABASE_URL=postgres://username:password@localhost:5432/mydatabase

Or use a .env file with:

DATABASE_URL=postgres://username:password@localhost:5432/mydatabase

Running the Application

Navigate to the project directory and run:

cargo run

The application will start and listen on 127.0.0.1:3000.

Usage

Shortening a URL

Make a POST request with JSON data:

{
    "url": "https://example.com",
    "user": "optional_username"
}

The response will contain the shortened key.

Accessing a URL

Navigate to http://localhost:3000/<key> to be redirected to the original URL. Each access will increment the visit count for that URL.

rs-short's People

Watchers

Levi King avatar  avatar

rs-short's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.