Skip to content

msaio/simple_shorten_url

Repository files navigation

Simple shorten URL

Documentation

For details about the URL shortening implementation, see URL Shortening Implementation.

For enhancement plans and URL normalization strategy, see Enhancement URL Normalization Strategy.

Local development

  • Install WSL v2 - Ubuntu 24.04
wsl --install -d Ubuntu
  • Dependencies
sudo apt-get update
sudo apt install build-essential rustc libssl-dev libyaml-dev zlib1g-dev libgmp-dev
  • Install mise - package management
curl https://mise.run | sh
echo 'eval "$(~/.local/bin/mise activate)"' >> ~/.bashrc
source ~/.bashrc
  • Ruby 3.4.3
mise use --global ruby@3
gem update --system
  • Rails 8.0.2
gem install rails -v 8.0.2
  • Postgres 16.9
sudo apt-get install build-essential libssl-dev libreadline-dev zlib1g-dev libcurl4-openssl-dev uuid-dev icu-devtools libicu-dev libicu74 pkgconf
pkg-config --libs --cflags icu-i18n icu-uc
mise use --global postgres@16
pg_ctl start

Access psql with

psql -U postgres

Create database role for current user

psql -U postgres -c "create role $USER"
psql -U postgres -c "alter role $USER SUPERUSER"
psql -U postgres -c "alter role $USER with login"
psql -U postgres -c "create database $USER"
psql -U $USER -c "\password"
  • Set up database
# Initialize .env follow .env.sanmple
rails db:create
rails db:migrate
  • Set up environment variables Ex: Create .env file
# Database configuration
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_HOST=
DATABASE_PORT=
DATABASE_CONNECTION_POOL=

# Rails environment
RAILS_ENV=
RAILS_MAX_THREADS=
HOST_DOMAIN=
  • Start server
cd <project_path>
rails s -p 3000 -b 0.0.0.0
  • Simulate endpoints call
./test_url_api.sh

# Run permission required
# chmdo +x test_url_api.sh

FAQs

Is the best practice?

  • No
  • This is a minimal viable implementation.
  • It currently supports just /encode and /decode endpoints for testing purposes.
  • The feature meets basic requirements, with all test cases passing successfully.
  • The extensive comments may seem excessive, but they ensure clarity when revisiting the code later.

About

A simple Rails application for shortening URL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published