A simple implementation of URL shortener built with Sinatra with a Redis backend.
To run this URL shortener, you need to first set up a Redis server. After that, you can start it as you would any other Rack app:
git clone https://github.com/isundaylee/short_url.git
rackup -p 3000 # start it on port 3000
A demo of this app can be found at http://jiahao.link
To create short URLs, simply go to http://yoursite.com
. You can both create short URLs with custom names or ones with automatically generated names.
To access a short URL, simply visit http://yoursite.com/name
(which is also returned to you in JSON after you created the short URL), and you will be redirected to the actual URL.
To create a short URL (you can also omit the name parameter to get a randomly generated name that could be as short as 2 characters):
POST /
Params: {'name': 'google', 'url': 'http://google.com'}
Response: {'url': 'http://example.com/google'}
To retrieve the actual URL:
GET /google
Response: {'actual_url': 'http://google.com'}
If you wanna contribute to this app, you can create issues, or submit a pull request as follows:
- Fork it.
- Create a branch (
git checkout -b new_feature
) - Commit your changes (
git commit -am "Implements an awesome feature. "
) - Push to the branch (
git push origin new_feature
) - Open a pull request
- Wait, while feeling good for your contribution :)