For a URL shortener service like Shortify, you would need several essential routes to handle shortening, redirecting, and managing URLs, along with user authentication and support for analytics. Below are the key routes you should consider for Shortify:
These routes are accessible without user authentication.
-
Route:
GET / -
Purpose: Displays the homepage where users can paste a long URL to shorten it.
-
Response: HTML page with a form to submit the URL.
-
Route:
POST /shorten -
Purpose: Accepts a long URL and returns a shortened URL.
-
Request Payload (JSON or Form Data):
{ "url": "https://www.example.com" } -
Response:
{ "shortened_url": "http://shortify.io/abc123" } -
Response for Custom URL:
{ "shortened_url": "http://shortify.io/customname" }
- Route:
GET /:shortCode - Purpose: Redirects the user to the original long URL based on the short code.
- Example:
GET /abc123- Redirects to the long URL associated with the short code
abc123(e.g.,https://www.example.com).
- Redirects to the long URL associated with the short code
- Response: HTTP 301/302 redirect to the original URL.
- Route:
GET /:shortCode/stats - Purpose: Returns statistics (e.g., number of clicks, referrers, countries, devices) for a particular shortened URL.
- Example:
GET /abc123/stats - Response:
{ "clicks": 150, "referrers": ["google.com", "facebook.com"], "countries": ["USA", "Canada"], "devices": ["desktop", "mobile"] }
These routes require the user to be logged in to access their shortened URL history, analytics, or manage custom URLs.
- Route:
GET /dashboard - Purpose: Displays a dashboard where authenticated users can manage all of their shortened URLs.
- Response: List of all URLs the user has shortened, along with options to edit or delete them.
-
Route:
POST /url/edit/:shortCode -
Purpose: Allows the user to edit the original URL or the short code.
-
Request Payload:
{ "new_url": "https://newurl.com", "new_short_code": "newshortcode" } -
Response: Success or error message.
-
Route:
DELETE /url/delete/:shortCode -
Purpose: Deletes a shortened URL created by the user.
-
Response: Success or error message.
These routes handle user registration, login, and account management.
-
Route:
GET /signup -
Purpose: Displays the signup page where users can create an account.
-
Response: HTML form to sign up.
-
Route:
POST /signup -
Purpose: Handles user registration by accepting username, email, and password.
-
Request Payload:
{ "username": "newuser", "email": "newuser@example.com", "password": "password123" } -
Response: Success or error message.
-
Route:
GET /login -
Purpose: Displays the login page.
-
Response: HTML form to log in.
-
Route:
POST /login -
Purpose: Authenticates the user using email and password.
-
Request Payload:
{ "email": "user@example.com", "password": "password123" } -
Response: Success message with session or token information.
- Route:
POST /logout - Purpose: Logs the user out by invalidating the session or token.
- Response: Success message.
- Route:
GET /pricing - Purpose: Displays a page with pricing information for premium users.
- Response: HTML page with pricing details.
-
Route:
POST /api/shorten -
Purpose: Allows developers to shorten URLs programmatically using an API key.
-
Request Payload (JSON):
{ "url": "https://www.example.com", "api_key": "user-api-key" } -
Response:
{ "shortened_url": "http://shortify.io/xyz789" } -
Route:
GET /api/:shortCode/stats -
Purpose: Provides programmatic access to URL analytics for developers.
-
Response (JSON):
{ "clicks": 200, "referrers": ["twitter.com", "linkedin.com"] }
- Route:
GET /support - Purpose: Displays a support page with FAQs and contact details.
- Response: HTML page with support information.
-
Route:
GET /terms -
Purpose: Displays the Terms of Service for the website.
-
Response: HTML page with legal information.
-
Route:
GET /privacy -
Purpose: Displays the Privacy Policy for the website.
-
Response: HTML page with details on data collection and usage.
| Route | Method | Description |
|---|---|---|
/ |
GET |
Displays homepage to shorten URLs. |
/shorten |
POST |
Shortens a URL and returns the shortened URL. |
/:shortCode |
GET |
Redirects to the original URL based on short code. |
/:shortCode/stats |
GET |
Displays analytics for a shortened URL. |
/dashboard |
GET |
Shows user's URL management dashboard. |
/url/edit/:shortCode |
POST |
Allows the user to edit a shortened URL. |
/url/delete/:shortCode |
DELETE |
Deletes a shortened URL. |
/signup |
GET |
Displays signup page. |
/signup |
POST |
Registers a new user. |
/login |
GET |
Displays login page. |
/login |
POST |
Logs the user in. |
/logout |
POST |
Logs the user out. |
This structure covers all the key features, from basic shortening to user management, API access, and analytics. You can add more routes depending on advanced features like paid plans or custom domains.