Giter Club home page Giter Club logo

shorten-urls's Introduction

Shorty

A micro service to shorten urls, such as TinyURL or bit.ly.

The app is build with:

  • Rack - pure rack, no framework is used.
  • Sequel
  • PostgreSQL
  • Redis is used as in-memory cache.

docker-compose run shorty bundle exec rspec

Usage

The application is dockerized, to start the server up, run the command:

docker-compose up

The app now is running on port 9292.

Tests

To run tests:

docker-compose run shorty bundle exec rspec

API Documentation

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_]{6}$.

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 /:shortcode/stats
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

shorten-urls's People

Contributors

lynfogeek avatar m-sayed avatar

Watchers

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