This is an example of a frontend UI for the Link Shortener API.
It allows users to shorten URLs, view shortened links, and receive status feedback through toast notifications.
- Basic input validation:
- Checks if the input URL is valid and includes a protocol (http:// or https://).
- Displays error messages for invalid or missing inputs.
- Local Storage:
- Caches previously shortened URLs for faster access.
- Avoids unnecessary API calls by checking local storage first.
- Dynamic UI Updates:
- Transitions between input and result sections smoothly.
- Displays the shortened URL after successful submission.
- Toast Notifications:
- Provides feedback for errors (e.g., missing protocol, invalid URL).
- User Input:
- The user enters a URL in the input field and submits it.
- Validation:
- The frontend checks if the URL is valid and includes a protocol.
- Local Storage Check:
- If the URL has been shortened before, the frontend retrieves the shortened URL from local storage.
- API Call:
- If the URL is not found in local storage, the frontend sends a request to the API to shorten the URL.
- UI Update:
- The frontend updates the UI to display the shortened URL.
- Error Handling:
- Displays appropriate error messages for invalid inputs or API failures.
- Enter a URL in the input field.
- Click the "Shorten" button.
- View the shortened URL in the result section.
- User enters
https://example.com
in the input field. - The frontend checks local storage and finds no match.
- The frontend sends a POST request to the API:
{
"url": "https://example.com"
}
- The API responds with:
{
"key": "abc123"
}
- The frontend displays the shortened URL:
https://jfa.ovh/abc123
.
- Toast Notifications: Managed by showToastWithTimeout utility.
- Local Storage: Used for caching shortened URLs.