Giter Club home page Giter Club logo

shortz's Introduction

Shortz: bare bones URL shortener ;)

Installation & usage

This is a bog standard Django + DRF (https://www.django-rest-framework.org/) app.

Best way to proceed:

  1. mkvirtualenv shortz
  2. pip install -r requirements.txt
  3. (cd shortz/ && ./manage.py migrate)
  4. (cd shortz/ && ./manage.py runserver)
  5. ready for testing

Testing

There are no unit tests, as those were not required. You can test the app using client of your choice (curl, Postman, restclient from Emacs what have you).

Here I'm showing result of using httpie per https://github.com/jakubroztocil/httpie#json

Valid URL shortening

$ http POST http://127.0.0.1:8000/shorten_url/ url=https://github.com/qazwsxpawel/

HTTP/1.1 201 Created
Allow: OPTIONS, POST
Content-Length: 181
Content-Type: application/json
Date: Tue, 31 Jul 2018 14:19:37 GMT
Server: WSGIServer/0.2 CPython/3.6.2
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
    "code": "oLMpI6NRP8GhPKoPa_UKUg",
    "date_created": "2018-07-31T14:19:37.074597Z",
    "shortened_url": "http://localhost:8000/oLMpI6NRP8GhPKoPa_UKUg",
    "url": "https://github.com/qazwsxpawel/"
}

Invalid URL handling

$ http POST http://127.0.0.1:8000/shorten_url/ url=https://github/qazwsxpawel/

HTTP/1.1 400 Bad Request
Allow: OPTIONS, POST
Content-Length: 30
Content-Type: application/json
Date: Tue, 31 Jul 2018 14:21:22 GMT
Server: WSGIServer/0.2 CPython/3.6.2
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

{
    "url": [
        "Enter a valid URL."
    ]
}

Retrieval

Open the returned URL in the browser (here: "http://localhost:8000/oLMpI6NRP8GhPKoPa_UKUg") and enjoy the redirect :)

Scaling

Not being an expert in the area I would apply this simple formula:

  • Load balancing
  • Placing API behind server-side cache e.g. Varnish ("a caching HTTP reverse proxy")
  • Caching the DB + ORM lookups

Next would be measuring bottlenecks in this simple application if any left (the biggest being the DB lookup).

Next steps

  1. Make the URL's actually short (those are OK, but not something you would like to type out)
  2. Fix TODO's

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.