Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
/ shortex Public archive

URL shortener API, based on top of GenServer & Registry (educational project)

Notifications You must be signed in to change notification settings

bdubaut/shortex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shortex

Build Status

To start the app:

  • Install dependencies with mix deps.get
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

API Documentation

Using only GenServers for the links is probably not the most scalable or reliable solution for this project, but it was fun to learn about this OTP behhaviour this way.

All responses are 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 /: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

About

URL shortener API, based on top of GenServer & Registry (educational project)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages