Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Shorty

URL shortening service like bit.ly implement with Sithara and Redis

API Documentation

POST /shorten

{
"url": "http://example.com",
"shortcode": "example"
}
AttributeDescription
urlurl to shorten
shortcodepreferential 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:
ErrorDescription
400url is not present
409The desired shortcode is already in use. Shortcodes are case-sensitive.
422The shortcode fails to meet the following regexp: ^[0-9a-zA-Z_]{4,}$.

GET /:shortcode

GET /:shortcode
Content-Type: "application/json"
AttributeDescription
shortcodeurl 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
ErrorDescription
404The shortcode is not found in the system

GET /:shortcode/stats

GET /:shortcode/stats
Content-Type: "application/json"
AttributeDescription
shortcodeurl 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
}
AttributeDescription
startDatedate when the url was encoded, conformant to ISO8601
redirectCountnumber of times the endpoint GET /shortcode was called
lastSeenDatedate of the last time the a redirect was issued, not present if redirectCount == 0
Errors
ErrorDescription
404The shortcode cannot be found in the system

Setup

All commands need to be run from the project folder.

$ ./setup.sh
$ bundle install

* change the setup.sh file permissions accordingly, if it shows 'Permission denied' while running.

Run

$ ruby app/service.rb. The app will running in http://localhost:4567

Tests

$ rspec

That's it. :-)

About

URL shortening service like bit.ly implemented with Sithara and Redis

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages