Coder Social home page Coder Social logo

dice's Introduction

#UrlShortener By Anders Martini

##Introduction This project uses DynamoDB as a backend to store a relation between shortened URL's and their full counterparts. Shortened Url's are derived from a MD5 hash, but using only the first 10 chars to keep it short.

Using a hashingalgorithm like MD5 ensures in a simple way that any given URL will get the same shortened url each time, while storing the relation in DynamoDB offloads the most difficult part of scalability to Amazon AWS.

The Code itself is written in the Micronaut framework, which is highly resource efficient, especially when, as in this case, it is combined with RxJava. RxJava provides Asynchronous IO, vastly improving the amount of load any given instance of the application can handle.

##Testing the application You have 2 options for testing this application. Unit-tests are provided and can be run either from your favourite IDE or via ./gradlew build. it should be noted that the database is mocked in this case.

Your other option is to run a local instance of DynamoDB, configure the application to target this local instance and set up credentials in a proper way. Just kidding - just execute run.sh ;).

This script requires Java 11, wget, and tar to be installed on your system beforehand.

##The API The application will start on port 8080 and has 2 endpoints. to create a shortened URL you can run the following: curl localhost:8080/shorten -d "https://andersmartini.com" -H "Content-Type: application/json"

it will return a string looking something like this: localhost:8080/dc87807a5

you can either paste that into your browser or curl it. if you use curl, remember to use the --location flag:

curl --location localhost:8080/dc87807a5

##Discussion This application uses a substring of a MD5 hash to generate shortened URLs and store them in a database. An alternative solution would be to use some sort of compression-algorithm to compress strings, and decompress them. This has the benefit of not requiring a database, and so is cheaper and easier to scale. However, it is unlikely to be able to shorten url's to as short a format as this application is doing, and certainly not static length as we do here: it would instead shorten the url's by some percentage of their original length.

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.