Git Product home page Git Product logo

urlshortener's Introduction

urlshortener

Simple, scalable, optionally replicated web service which can shorten and expand a URL, in a tinyurl / bitly fashion.

This project is primarily a thought exercise and a way of trying out a few different ideas. It was built using TDD/BDD so should have good test coverage. Particular attention has been paid to efficient use of RAM, and fast shortening/expansion of tokens.

The URL shortener is a JSON web service, and does not have a pretty GUI for ordinary web users. In a future iteration I may add a GUI.

There are three 'databases' available:

  1. An optimised RAM based map, which can persist to disk. Limited by available RAM.
  2. A MapDB backed disk store which can support significantly larger data sets. Limited by disk space.
  3. A MapDB+JGroups distributed store which can replicate across multiple servers. Limited by disk space.

Configuration

There is a config.properties file which configures the system.

BASE_URL=http://b.io/
DISK_BACKUP_FILEPATH=/var/lib/urlshortener/backup.mapdb
DATABASE_FACTORY_CLASSPATH=com.perry.urlshortener.persistence.BigOrderedReplicatedMapDBSetFactory
REPLICATION_CLUSTER_NAME=urlshortenermap
REPLICATION_TIMEOUT_MS=5000

If you have multiple instances running on the same file system, you will need to give each instance a different backup file path. This can be done by starting the JVM with -DDISK_BACKUP_FILEPATH=/var/lib/urlshortener/backup_2.mapdb (for example).

Usage

Assuming the system is running on http://b.io/,

To shorten a URL: http://b.io/?shorten=http://some.url/etc/

This will return a shortened URL e.g. http://b.io/jhakdj Hitting that URL will take you to the originally shortened URL.

To view the expanded URL without redirecting to it, simply add a + http://b.io/xhgjgh+

A JSONP service also exists to allow manipulatin of URLs with JavaScript. Simply add a ?callback= parameter to the request, e.g.

http://b.io/xhghg?callback=myfunc

This will return e.g.

myfunc({"url": "http://fred.1"});

Equally shortening a URL can return JSONP responses;

http://b.io/?shorten=http://bob&callback=myfunc

myfunc({"url": "http://b.io/ashdk"});

Future Improvements

  • The service could be improved upon with support for whitelists.
  • Cloudbase could be used as a database - this would likely be a more robust storage solution.

References

urlshortener's People

Contributors

4dz avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.