URL Shortener is a web-based application that allows users to input long URLs and generate shortened links. This project leverages an intuitive interface for a seamless user experience, with the added feature of copying the shortened URL to the clipboard directly.
Technologies Used
- Frontend: HTML, CSS, TypeScript
- Backend: None (API Integration with
axios
) - API: Various URL shortening APIs (e.g.,
shrtco.de
,tinyurl.com
) - Libraries & Tools:
- Toastify.js (Notification System)
- Axios (HTTP Client)
- Tailwind CSS (UI Styling)
- Vite (Build Tool)
Features
-
URL Shortening:
- Allows users to shorten URLs through an external API service.
- Displays the shortened URL in the input field for easy access.
-
Clipboard Copying:
- Users can click a button to copy the shortened URL directly to the clipboard.
- Provides feedback through visual notifications using Toastify.js.
-
Real-Time Validation:
- Automatically validates the URL format before submission.
- Shows warnings for invalid URLs.
-
User-Friendly Interface:
- Simple form for URL input and output.
- Responsive design for various screen sizes.
-
Notifications:
- Provides real-time feedback when a URL is successfully shortened or when an error occurs.
Code Architecture
The core functionality is encapsulated in the Shortener
class, which handles:
- Initialization: Dynamically creates and renders the DOM elements for the form and buttons.
- Event Handling: Tracks user input and form submissions, handling URL validation and API requests.
- State Management: Manages the form state, error messages, and success responses.
- API Integration: Uses external URL shortening APIs to generate shortened URLs.
- Clipboard Handling: Manages the copy-to-clipboard functionality for the shortened URL.
- Notification System: Uses Toastify.js to provide user feedback on actions performed.