For freeCodeCamp - Back end > API Projects > URL Shortener Microservice
-
I can pass a URL as a parameter and I will receive a shortened URL in the JSON response.
-
If I pass an invalid URL that doesn't follow the valid http://www.example.com format, the JSON response will contain an error instead.
-
When I visit that shortened URL, it will redirect me to my original link.
// Generate new short URL:
https://url-shortener-js.glitch.me/new/http://www.example.com
// Accesses a previously generated short URL:
https://url-shortener-js.glitch.me/5178
{
"original_url": "http://www.example.com",
"short_url": "https://url-shortener-js.glitch.me/5178"
}
{
"error": "Invalid URL."
}