Create a micro service to shorten urls like bit.ly or TinyURL do.
- The service must expose HTTP endpoints according to the API Docs below.
- Use your technology of choice, there's no restrictions. Instructions for the installation must be detailed in the INSTALL.md file.
- Write the tests you consider necessary.
POST /urls
Content-Type: "application/json"
{
"url": "http://example.com",
"code": "example"
}
- url: URL to shorten. Required
- code: Desired shortcode. Alphanumeric, case-sensitive 6 chars lenght.
Note: If code is not provided, a random code, with the same constraints, must be generated
201 Created
Content-Type: "application/json"
{
"code": :shortcode
}
- Bad Request: If
url
is not present - Conflict: If the the desired shortcode is already in use.
- Unprocessable Entity: If the shortcode doesn't doesn't comply with its description.
GET /:code
Content-Type: "application/json"
- code: Encoded URL shortcode
It's a redirect response including the target URL in its Location
header.
HTTP/1.1 302 Found
Location: http://www.example.com
- Not Found: If the
shortcode
cannot be found
GET /:code/stats
Content-Type: "application/json"
- code: Encoded URL shortcode
200 OK
Content-Type: "application/json"
{
"created_at": "2012-04-23T18:25:43.511Z",
"last_usage": "2012-04-23T18:25:43.511Z",
"usage_count": 1
}
start_date
: ISO8601 formatted date when the shortened URL was createdusage_count
: Number of requests to the endpointGET /code
last_usage
: Date of the last time the shortened URL was requested. Not included if it has never been requested.
- Not Found: If the
shortcode
cannot be found
- Fork this repo to your own Github account.
- Implement the functionality, including any instructions to setup and run the application.
- Submit a PR to the
master
branch of this repository.
Thank you and good luck!