API

The API endpoints listed below are available.

POST /api/save

Create a shorter URL.

Request

To obtain a short URL make a POST request with a JSON payload. The url key must be included and its value set to the URL you want shortened.

$ curl -H"Content-Type: application/json" \
-X POST -d '{"url":"http://example.com"}' \
  http://example.com/api/save
  
Response

The response includes both the key and the shortUrl.

{
  "key":"rt",
  "shortUrl":"http://example.com/rt"
}
  

GET /api/get/:key

Lookup an original URL by its associated key. The key must be included as the final path in the API endpoint path.

Request

To obtain the original URL for a key, make a GET request with the key as part of the URL.

$ curl http://localhost:3100/api/get/fg
  
Response
The response is a JSON payload with a url containing the original URL.
{
  "url":"http://example.com"
}
  

GET /api/recent

Retrieve a list of the 10 most recently shortened URLs.

Request

No arguments.

$ curl http://localhost:3100/api/recent
  
Response

A JSON payload is returned with the recentUrls key associated with an array of URLs.

{"recentUrls":["http://example.com"]}