A simple URL shortener made with Ruby & Sinatra
docker-compose up
Server is running on localhost:8080
APP_ENV=production
NANOID_SIZE=11 # Length of short-URLs
REDIS_URL=redis:https://localhost:6379
DATABASE_HOST=localhost:5432
DATABASE_NAME=postgres
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
bundle install
bundle exec rake db:migrate
bundle exec puma -p 80
Clone the repository and open the Dev Container in VSCode, run
bundle exec rake db:migrate
bundle exec puma
Development server will be forwarded to localhost:9292
bundle exec rake spec:all
GET /{url}
Parameter Type Description json
"true"|"false"
Return JSON response, otherwise redirects JSON Response
{ "exists": boolean, "target": string }The
exists
attribute is true if the URL exists.The
target
attribute is the destination URL, to be used for redirecting.NOTE: Status code
404
is returned if the URL does not exist.
POST /
Parameter Type Description response_html
"true"|"false"
Return HTML response (used by the frontend), otherwise JSON JSON Response
{ "url_full": string "url": string "base_url": string "target": string }The
url_full
attribute is the full short-URL, equivalent to{base_url}/{url}
.The
url
attribute is the resulting URL slug.The
base_url
attribute is the protocol and domain part of the short-URL.The
target
attribute is the destination URL, to be used for redirecting.