This service accepts a URL as a parameter and will check whether it follows the valid https://www.google.com format. If the URL is valid, it will return both the original URL and shortened URL in the JSON response. If it is not valid, the JSON response will contain an error instead. When you visit that shortened URL, it will redirect you to the original link.
- I can POST a URL to
[project_url]/api/shorturl/new
and I will receive a shortened URL in the JSON response. Example :{"original_url":"www.google.com","short_url":1}
- If I pass an invalid URL that doesn't follow the valid
http(s)://www.example.com(/more/routes)
format, the JSON response will contain an error like{"error":"invalid URL"}
. HINT: to be sure that the submitted url points to a valid site you can use the functiondns.lookup(host, cb)
from thedns
core module. - When I visit the shortened URL, it will redirect me to my original link.
POST [project_url]/api/shorturl/new - body (urlencoded) : url=https://www.google.com
[this_project_url]/api/shorturl/3