Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
/ briefly Public archive

Rust-based URL shortener using Axum and SQLx deployed on Shuttle.rs 🚀

Notifications You must be signed in to change notification settings

adrianEffe/briefly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Briefly

CI (master) CD (master)

Briefly is a URL shortener service built with Rust, using the Axum web framework and SQLx for database interactions. It's a simple and efficient tool designed to shorten long URLs, making them easier to manage and share. This README provides an overview of Briefly's features and how to use it.

Features

  1. URL Shortening: Briefly takes long URLs and shortens them, creating concise and easy-to-share links.

  2. Custom URL Extensions: You can define custom extensions for your shortened URLs. For example, if you shorten "https://www.rust-lang.net" with the custom extension "rust," the shortened URL will be accessible at https://briefly.shuttleapp.rs/rust.

  3. Random Extensions: If you don't specify a custom extension, Briefly generates a unique, random extension consisting of 7 characters.

  4. Health Check: The service is live and available at https://briefly.shuttleapp.rs. You can perform a health check by running:

    curl --verbose https://briefly.shuttleapp.rs/health_check

    A successful response (HTTP status code 200) indicates that the service is up and running.

How to Shorten URLs

To shorten a URL using Briefly, you can use the following curl command as an example:

curl --header "Content-Type: application/json" \
--data '{"url":"https://www.rust-lang.net"}' \
https://briefly.shuttleapp.rs/shorten

This command sends a POST request to the service, specifying the original URL and the custom extension you want to use. If successful, Briefly will generate a unique, random extension for your shortened URL:

{
    "extension": "AsYuFAW"
}

You can then access the shortened URL at https://briefly.shuttleapp.rs/AsYuFAW.

Note you can defined a custom extension like below, but if it is already taken a HTTP status 500 will be returned.

   curl --header "Content-Type: application/json" \
  --data '{"url":"https://www.rust-lang.net","extension":"rust"}' \
  https://briefly.shuttleapp.rs/shorten

Expect a response like this:

{
    "extension": "rust"
}

You can then access the shortened URL at https://briefly.shuttleapp.rs/rust.

How to Run

To run the Briefly service locally, follow these steps:

- Install Dependencies

Install Rust, PostgreSQL, and Docker on your system.

- Initialize Shuttle

Run the following commands to set up the Shuttle environment:

cargo shuttle init

For more detailed information regarding Shuttle, refer to the Shuttle Documentation.

- Start the Project

Start the Shuttle project with the following command:

cargo shuttle project start

- Initialize the Database:

This step is needed in order to run tests, otherwise feel free to skip this step, shuttle will take care of the rest. Run the following command to make the initialization script executable:

chmod +x scripts/init_db.sh

Launch PostgreSQL using the script:

./scripts/init_db.sh

- Run the Service

Start the Briefly service with the following command:

cargo shuttle run

About

Rust-based URL shortener using Axum and SQLx deployed on Shuttle.rs 🚀

Topics

Resources

Stars

Watchers

Forks