Coder Social home page Coder Social logo

vipulchandan / urlshortener Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 20 KB

URLShortener project is a URL shortener API developed using Node.js and Express.js. It utilizes MongoDB as the database for storing the shortened URLs and Redis for caching. It generates short IDs using the shortid library and validates URLs using the valid-url library, allowing users to shorten long URLs and retrieve the original URL

Home Page: https://general-polite-banon.glitch.me/

JavaScript 100.00%
axios expressjs javascript mongodb nodejs redis shortid valid-url

urlshortener's Introduction

Scalable URL Shortner Project Requirement

Phase I

Overview

URL shortening is used to create shorter aliases for long URLs. We call these shortened aliases “short links.” Users are redirected to the original URL when they hit these short links. Short links save a lot of space when displayed, printed, messaged, or tweeted. Additionally, users are less likely to mistype shorter URLs.

For example, if we shorten the following URL through TinyURL:

https://babeljs.io/blog/2020/10/15/7.12.0#class-static-blocks-12079httpsgithubcombabelbabelpull12079-12143httpsgithubcombabelbabelpull12143

We would get:

https://tinyurl.com/y4ned4ep

The shortened URL is nearly one-fifth the size of the actual URL.

Some of the use cases for URL shortening is to optimise links shared across users, easy tracking of individual links and sometimes hiding the affiliated original URLs.

If you haven’t used tinyurl.com before, please try creating a new shortened URL and spend some time going through the various options their service offers. This will help you have a little context to the problem we solve through this project.

Key points

  • Create a group database groupXDatabase. You can clean the db you previously used and reuse that.
  • This time each group should have a single git branch. Coordinate amongst yourselves by ensuring every next person pulls the code last pushed by a team mate. You branch will be checked as part of the demo. Branch name should follow the naming convention project/urlShortnerGroupX
  • Follow the naming conventions exactly as instructed. The backend code will be integrated with the front-end application which means any mismatch in the expected request body will lead to failure in successful integration.

Models

  • Url Model
{ urlCode: { mandatory, unique, lowercase, trim }, longUrl: {mandatory, valid url}, shortUrl: {mandatory, unique} }

POST /url/shorten

  • Create a short URL for an original url recieved in the request body.
  • The baseUrl must be the application's baseUrl. Example if the originalUrl is http://abc.com/user/images/name/2 then the shortened url should be http://localhost:3000/xyz
  • Return the shortened unique url. Refer this for the response
  • Ensure the same response is returned for an original url everytime
  • Return HTTP status 400 for an invalid request

GET /:urlCode

  • Redirect to the original URL corresponding
  • Use a valid HTTP status code meant for a redirection scenario.
  • Return a suitable error for a url not found
  • Return HTTP status 400 for an invalid request

Testing

  • To test these apis create a new collection in Postman named Project 2 Url Shortner
  • Each api should have a new request in this collection
  • Each request in the collection should be rightly named. Eg Url shorten, Get Url etc
  • Each member of each team should have their tests in running state

Phase II

+Consider that Twitter has this trend where a famous person with a wide following when posts a link, the link gets frequented in millions within a day.

+So in our application we would want to implement caching so that a newly created link is cached for 24 hours. When a person uses a short url, the long url should be retrieved from cache in the first 24 hours of that url being created.

+- Use caching while fetching the shortened url to minimize db calls.
+- Implement what makes sense to you and we will build understanding over the assessment of this project. You should understand and should be able to explain the logic that you have implemented.

Response

Successful Response structure

{
  status: true,
  data: {

  }
}

Error Response structure

{
  status: false,
  message: ""
}

Response samples

Url shorten response

{
  status: true,
  "data": {
    "longUrl": "http://www.abc.com/oneofthelongesturlseverseenbyhumans.com",
    "shortUrl": "http://localhost:3000/ghfgfg",
    "urlCode": "ghfgfg"
  } 
}

urlshortener's People

Contributors

vipulchandan avatar

Stargazers

 avatar

Watchers

 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.