This is an example of URL shortener service in Ruby.
- Redis 1.2+ (if you have and older version you need to comment out this lines):
require "hiredis" # speeds up the redis, works only with Redis 1.2+
require "redis/connection/hiredis" # defining Hiredis backend for redis-rb
- Ruby with this gems:
bundle install
Just exec rackup
and point your browser to http://localhost:9292/
for shortener form.
If you want to get response as JSON, add require 'json'
at the top of shortener.rb
and
post "/u" do
content_type :json
{url_or_whatever: put_url(params[:url])}
end
instead of similar block at the bottom.