0.3.0 • Published 7 years ago

@augmt/url-shortener-microservice v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

URL Shortener Microservice

Shorten long URLs.

How it Works

This microservice uses Monk to store and retrieve objects, normalize-url and random-js to normalize URLs and generate unique aliases, the WHATWG URL API to validate URLs, and Koa and koa-router to serve requests.

How to Use

app.js exports a Koa app. Koa apps have an app.listen() method that is identical to Node's http.Server.listen().

Import app.js and call app.listen() to start up the microservice.

Environment Variables

  • MONGO_URI - your Mongo database's connection string

API Resources

POST /new/:url

Returns a ShortUrl object.

REQUEST

Sample: https://url-shortener-microservice.example.com/new/http://example.com

RESPONSE

Status: 200 - application-json

Response:

{  
  "originalurl": "http://example.com/",
  "shorturl": "http://url-shortener-microservice.example.com/6uZ"
}

GET /:alias

Redirects the client to the corresponding long URL.

REQUEST

Sample: https://url-shortener-microservice.example.com/6uZ

RESPONSE

Status: 302

Location: http://example.com/