Your URL Shortener App is a web application that allows users to shorten long URLs, manage their generated short URLs, and more. This README provides comprehensive documentation for both the backend and frontend components.
To get started, clone the repository to your local machine:
git clone https://github.com/ajayahara/short-url.git
- Node.js installed
- Pnpm installed
- Mongo DB database
# Navigate to the backend directory
cd backend
# Install dependencies
pnpm install
Create a .env
file in the backend
directory with the following variables:
PORT=3001
URI=your-mongodb-uri
SECRETKEY='your-secret-key'
# Start the backend server
pnpm dev
# Navigate to the frontend directory
cd frontend
# Install dependencies
pnpm install
Create a .env
file in the frontend
directory with the following variables:
VITE_SERVER=http://localhost:3001
# Start the developement server
pnpm dev
The Authentication API provides endpoints for user registration and login.
Register a new user with the provided details.
- Method:
POST
- URL:
auth/register
- Headers:
- Content-Type: application/json
- Body:
userName
(string, required): User's username.email
(string, required): User's email address.password
(string, required): User's password.
- Status Code: 201 Created
- Body:
{ "message": "User registered successfully" }
Login an existing user with the provided email and password.
- Method:
POST
- URL:
auth/login
- Headers:
- Content-Type: application/json
- Body:
email
(string, required): User's email address.password
(string, required): User's password.
- Status Code: 200 OK
- Body:
{ "token": "generated-jwt-token", "userName": "user-username" }
-
400 Bad Request:
- If some fields are missing or invalid.
-
401 Unauthorized:
- If the user does not exist or invalid credentials.
-
500 Internal Server Error:
- If there's an error during registration or login.
Create a new short URL with the provided information.
- Method:
POST
- URL:
url/create
- Headers:
- Authorization Token: Bearer
<Your_JWT_Token>
- Content-Type: application/json
- Authorization Token: Bearer
- Body:
originalUrl
(string, required): Original URL to be shortened.title
(string, required): Title for the short URL.description
(string, required): Description for the short URL.startDate
(string): Start date for the short URL (optional).expireDate
(string, required): Expiration date for the short URL.
- Status Code: 201 Created
- Body:
{ "newUrl": { "_id": "generated-url-id", "originalUrl": "original-url", "userId": "user-id", "title": "short-url-title", "description": "short-url-description", "startDate": "start-date", "expireDate": "expire-date", "shortId": "generated-short-id", "createdAt": "timestamp", "updatedAt": "timestamp" } }
-
400 Bad Request:
- If some fields are missing or invalid.
-
500 Internal Server Error:
- If there's an error during the URL creation.
Retrieve a paginated list of all shortened URLs for the authenticated user.
- Method:
GET
- URL:
url/get/all
- Headers:
- Authorization Token: Bearer
<Your_JWT_Token>
- Authorization Token: Bearer
- Query Parameters:
page
(integer): Page number for pagination (optional, default: 1).limit
(integer): Number of items per page (optional, default: 10).order
(string): Sort order for items (optional, default: "desc").
- Status Code: 200 OK
- Body:
{ "shortUrls": [ { "_id": "url-id-1", "originalUrl": "original-url-1", "userId": "user-id", "title": "short-url-title-1", "description": "short-url-description-1", "startDate": "start-date-1", "expireDate": "expire-date-1", "shortId": "generated-short-id-1", "createdAt": "timestamp-1", "updatedAt": "timestamp-1" }, // Additional short URLs... ] }
- 500 Internal Server Error:
- If there's an error during the retrieval of shortened URLs.
Retrieve details of a specific shortened URL by its ID for the authenticated user.
- Method:
GET
- URL:
url/get/:id
- Headers:
- Authorization Token: Bearer
<Your_JWT_Token>
- Authorization Token: Bearer
- URL Parameters:
id
(string): ID of the shortened URL to retrieve.
- Status Code: 200 OK
- Body:
{ "shortUrl": { "_id": "url-id", "originalUrl": "original-url", "userId": "user-id", "title": "short-url-title", "description": "short-url-description", "startDate": "start-date", "expireDate": "expire-date", "shortId": "generated-short-id", "createdAt": "timestamp", "updatedAt": "timestamp" } }
-
400 Bad Request:
- If the provided ID is invalid.
-
500 Internal Server Error:
- If there's an error during the retrieval of the shortened URL.
Modify details of a specific shortened URL by its ID for the authenticated user.
-
Method:
PATCH
-
URL:
url/modify/:id
-
Headers:
- Authorization Token: Bearer
<Your_JWT_Token>
- Content-Type: application/json
- Authorization Token: Bearer
-
URL Parameters:
id
(string): ID of the shortened URL to modify.
-
Body:
{ "title": "new-title", "description": "new-description", "expireDate": "new-expire-date" }
-
Status Code: 200 OK
-
Body:
{ "message": "Shortened URL updated" }
-
400 Bad Request:
- If the provided ID is invalid.
-
500 Internal Server Error:
- If there's an error during the retrieval of the shortened URL.
Delete a specific shortened URL by its ID for the authenticated user.
- Method:
DELETE
- URL:
url/delete/:id
- Headers:
- Authorization Token: Bearer
<Your_JWT_Token>
- Authorization Token: Bearer
- URL Parameters:
id
(string): ID of the shortened URL to delete.
- Status Code: 200 OK
- Body:
{ "message": "Shortened URL along with visitors deleted" }
-
400 Bad Request:
- If the provided ID is invalid.
-
500 Internal Server Error:
- If there's an error during the retrieval of the shortened URL.
Redirects to the original URL associated with the given short ID.
- Method: GET
- URL:
/:shortId
shortId
(string, required): Short ID associated with the URL.
- Status Code: 302 Found (Redirect)
- Redirect: Redirects to the original URL
-
Status Code: 400 Bad Request
- Message: No short URL found with this short ID.
-
Status Code: 500 Internal Server Error
- Error: Error while finding all visitors.
API for retrieving visitor information related to a specific URL.
- Method: GET
- URL:
/get/:urlId
urlId
(string, required): ID of the URL for which visitor information is requested.
This endpoint requires authorization.
- Status Code: 200 OK
- Body: JSON object containing the array of visitors.
{
"visitors": [
{
"ipAddress": "127.0.0.1",
"urlId": "urlId1",
"referFrom": "http://referer.com",
"createdAt": "2023-01-01T12:00:00.000Z"
},
// Additional visitors...
]
}
-
Status Code: 400 Bad Request
- Message: No short URL found with this ID.
-
Status Code: 500 Internal Server Error
- Error: Error while finding all visitors.
The frontend of the project is organized into the following pages:
- Login
- Register
- Home
- About
- All URLs
- Details
- Not Found
-
Login Page
-
Register Page
-
Home Page
-
About Page
-
All URLs Page
-
Details Page
-
Not Found Page
- React: A JavaScript library for building user interfaces.
- React Router: Declarative routing for React.js.
- Tailwind CSS: A utility-first CSS framework.
Thank you for considering contributing to our project! Whether it's reporting a bug, suggesting a feature, or submitting a pull request, we appreciate your involvement. To contribute, please follow these guidelines:
-
Bug Reports: If you encounter any issues, please create a detailed bug report with information on how to reproduce the problem.
-
Feature Requests: If you have ideas for new features or improvements, feel free to submit a feature request. Describe the proposed functionality and its use case.
-
Pull Requests: We welcome contributions! If you have code changes you'd like to make, open a pull request with a clear description of the changes.
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature-name
. - Make your changes and commit them:
git commit -m 'Add new feature'
. - Push the changes to your branch:
git push origin feature-name
. - Open a pull request.
This project is licensed under the MIT License.