Code Monkey home page Code Monkey logo

urlshortener's Introduction

URL Shortener Backend Developer -

This is a Django project that implement a URL Shortener with hit count for each shorten link.

Short URL -

The Short Url is saved as 6 characters of Base62, using _generate_rand_str method. It stored in the "short_path" CharField field in the URLMapper Model. "short_path" field enforce unique=True, hence it maintain unique property. "short_path" currently limited to 6 characters, that ensure 62^6 unique identifiers. Notice: 62^6 = 5.68 x 10 ^ 10 unique identifiers.

When it will not be enough, two main options to solve it are:

  1. reused "short_path" identifiers that wasn't been in use for a long period of time.
  2. raise the "short_path" identifier length by 1 will ensure us additional large range of unused unique identifiers.

Hit Count logic -

Update: Is made by calling: 'UrlMapper.objects.filter(short_path=kwargs['pk']).update(hits=F('hits')+1)', from the RedirectViewUrl.get_redirect_url.

Exists in the URLMapper model as PositiveBigIntegerField field named "hits". Increment by 1, by calling URLMapper.increase_hits from the RedirectViewUrl view. Each hit will create or update the browser cache, and will cause subsequent requests to fullfill by the browser cache. Request that will not reach to our view, will not increase the hit counter.

Note: Each Session expire after two weeks (default value of SESSION_COOKIE_AGE).

unittest -

There are 3 tests for the CreateViewShortener:

  1. test_createapiview_get_200 - Test the 200 response status code, when calling a GET on the create_url_mapper.
  2. test_createapiview_create_valid_url - Test the creation of a URLMapper and the status code, using valid data.
  3. test_createapiview_create_invalid_url - Test the create_url_mapper, using invalid URL string.

There are 2 tests for the RedirectViewUrlTest:

  1. test_redirect_url - Test the correct redirect process, using a valid short path.
  2. test_redirect_non_existing_url - Test the process of an invalid short path as input.

Additional modifications -

  1. Change RedirectViewUrl.permanent attribute to True, so the browser will cache the address. Only the initial request will reach the server. Any subsequent request will be handled by the browser.

Future Improvements -

  1. To Add User management option. A User should manage its own items and modify them.
  2. Maybe to Add a feature that could collect data about the hits (location, etc) using kafka.

urlshortener's People

Contributors

liora1 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.