Git Product home page Git Product logo

url-shortener's Introduction

README

How the URL shortener works.

This rails 5 URL shortener consists of 3 endpoints that allow the react app: www.cuturl.work to fetch and post data into the systems DB.

  • /top.json ( For the top 100 URLS) This endpoint consists of a query that limits results to 100 and makes sure that we pull only records that have a "hit" count greater than 0. The response object is an array of arrays containing the necessary data that the ReactJS app table will be displaying, the url hash and the hit count.

  • /url.json This is a POST endpoint that receive a single parameters: "url". This is basically the url that the end user will be submitting into the input box and therefore will be sent to Rails to process it and create a short hash.

The hashing algorithm chosen was the one similar to Reddit's post and TinyURL's shortening algorithm. To make sure that a url is always unique we use the new URL record's id, stringify it and convert it to a base36 string, afterwards an automatically random generated short hex is appended to it to make sure the new hashes are not easily guessed.

The endpoint's response object is a json with a single key caled : short_url that the ReactAPP uses to showcase to the end user.

  • /:short_hash

This is a GET endpoint that looks for an existing record in the database, it basically looks for the param[:short_hash] in the database and if it exists it will return a json with a single key called: "long_url" that the reactAPP uses for redirecting the end user.

This API was testing driven developed using RSpec, every method developed has its respective spec.

As suggested, the database chosen for this scenario is a Postgresql simply for convienience as this is my database of choice for quick development projects.

The chosen deployment hosting was: Heroku free dyno with heroku's free RedisToGo to run sidekiq's background job of updating the title of url.

url-shortener's People

Contributors

ja-roque 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.