Giter Site home page Giter Site logo

shorty's Introduction

Install and Run

Clone the repo

  git clone https://github.com/matheusclmb/shorty.git

Install the requirements

  pip install -r requirements.txt

Run with Python

  python app.py

Shorty Challenge

The trendy modern question for developer inteviews seems to be, "how to create an url shortner". Not wanting to fall too far from the cool kids, we have a challenge for you!

The Challenge

The challenge, if you choose to accept it, is to create a micro service to shorten urls, in the style that TinyURL and bit.ly made popular.

Rules

  1. The service must expose HTTP endpoints according to the definition below.
  2. The service must be self contained, you can use any language and technology you like, but it must be possible to set it up from a fresh install of Ubuntu Server, by following the steps you write in the README.
  3. It must be well tested, it must also be possible to run the entire test suit with a single command from the directory of your repository.
  4. The service must be versioned using git and submitted by making a Pull Request against this repository, git history should be meaningful.
  5. You don't have to use a datastore, you can have all data in memory, but we'd be more impressed if you do use one.

Tips

  • Less is more, small is beautiful, you know the drill โ€” stick to the requirements.
  • Don't try to make the microservice play well with others, the system is all yours.
  • No need to take care of domains, that's for a reverse proxy to handle.
  • Unit tests > Integration tests, but be careful with untested parts of the system.

Good Luck! โ€” not that you need any ;)


API Documentation

All responses must be encoded in JSON and have the appropriate Content-Type header

POST /shorten

POST /shorten
Content-Type: "application/json"

{
  "url": "http://example.com",
  "shortcode": "example"
}
Attribute Description
url url to shorten
shortcode preferential shortcode
Returns:
201 Created
Content-Type: "application/json"

{
  "shortcode": :shortcode
}

A random shortcode is generated if none is requested, the generated short code has exactly 6 alpahnumeric characters and passes the following regexp: ^[0-9a-zA-Z_]{6}$.

Errors:
Error Description
400 url is not present
409 The the desired shortcode is already in use. Shortcodes are case-sensitive.
422 The shortcode fails to meet the following regexp: ^[0-9a-zA-Z_]{4,}$.

GET /:shortcode

GET /:shortcode
Content-Type: "application/json"
Attribute Description
shortcode url encoded shortcode
Returns

302 response with the location header pointing to the shortened URL

HTTP/1.1 302 Found
Location: http://www.example.com
Errors
Error Description
404 The shortcode cannot be found in the system

GET /:shortcode/stats

GET /:code
Content-Type: "application/json"
Attribute Description
shortcode url encoded shortcode
Returns
200 OK
Content-Type: "application/json"

{
  "startDate": "2012-04-23T18:25:43.511Z",
  "lastSeenDate": "2012-04-23T18:25:43.511Z",
  "redirectCount": 1
}
Attribute Description
startDate date when the url was encoded, conformant to ISO8601
redirectCount number of times the endpoint GET /shortcode was called
lastSeenDate date of the last time the a redirect was issued, not present if redirectCount == 0
Errors
Error Description
404 The shortcode cannot be found in the system

shorty's People

Contributors

kyotometus avatar vasc 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.