Shortbread

preview
  • express

  • node

  • api

  • microservice


  • Shortbread is a microservice for shortening urls. It was built as part of the FreeCodeCamp api and microservices challenges. The form accepts a url

    which, when posted, will call the api and return a JSON object with the format:

    {
      "original_url": "https://www.google.com",
      "short_url": "595c3cc"
    }
    

    This short url can be used to forward to the original url. Simply visit https://shortbread-url.herokuapp.com/api/shorturl/595c3cc and you will be forwarded to www.google.com.

    These url pairs are held in a database so that another user attempting to shorten the url https://www.google.com will recieve the same short url 5953cc. In this manner, the short urls are shareable.

    If you are wondering why anyone would share a shortened url that is significantly longer than the original, please note the folllowing:

    • This microservice is hosted for free at Heroku, and does not have a custom domain. Fully deployed, one would choose a short domain such as https://shortb.read or something even shorter such as https://shtb.red.
    • The subsequent/api/shorturl/ is also required to pass the tests on FreeCodeCamp. In reality, you would eschew that entirely and end up with, if we continue our example above, a short url more like https://shortb.read/595c3cc. Now, I grant that that is still not shorter, but you can imagine a huge number of urls exist which are much longer than that, and that is the maximum length of a shortbread url. So it would be useful in such a scenario.

    A working demonstration is hosted at Heroku, and you can visit it and try it out using the visit website button at the top of this page. The code is hosted at Github and you can visit this using the github button, also at the top of this page.