A simple redirect server / URL shortener.
An example of how to use nodeuv-http
.
./server
To shorten a urlencoded long url, add a url
parameter to the query
string with its value encoded.
PUT http://mic.cm/shorten?url=http%3A%2F%2Fmic.com%2Fmy-long-url
HTTP/1.1 200 OK
Content-Type: plain/text
aZ9yB
To redirect to long url, look up the url by the provided id and respond
with a 301
to the client with the long version of the url.
GET http://mic.cm/aZ9yB
HTTP/1.1 301 Moved Permanently
Location: http://mic.com/my-long-url
When the /shorten
api call is made on an existing url, the url is looked
up and if it's already shortened, the existing id is returned.
PUT http://mic.cm/shorten?url=http%3A%2F%2Fmic.com%2Fmy-long-url
HTTP/1.1 200 OK
Content-Type: plain/text
aZ9yB