Features

  1. Shorten URLs

    Generate short links with either custom aliases or randomly generated short codes.

  2. Expiration Dates

    Set an optional expiration date for each URL. Links without expiration remain active indefinitely.

  3. Analytics

    Track the total number of clicks on each short URL and view detailed stats.

  4. User Authentication

    Secure registration and login using JWT-based authentication for managing user-specific URLs.

  5. Cookie-Based Sessions

    Manage secure sessions with encrypted cookies for better security and persistence.

  6. MongoDB Integration

    All link data, user details, and analytics are stored securely in MongoDB.


Tech Stack


API Endpoints Documentation

List of available endpoints for the URL Shortener Application.

User Routes

Method Endpoint Description
GET /api/v1/users Fetch all users (requires token)
GET /api/v1/users/:id Fetch a specific user by ID (requires token)
POST /api/v1/users/login Login user
POST /api/v1/users/logout Logout user (requires token)
POST /api/v1/users/register Register a new user
PUT /api/v1/users/:id Update user info (requires token)
DELETE /api/v1/users/:id Delete a user (requires token)

URL Routes

Method Endpoint Description
GET /api/v1/urls Fetch all URLs for the logged-in user (requires token)
GET /api/v1/urls/:id Fetch short URL by ID (requires token)
POST /api/v1/urls Generate a new short URL (requires token)
PUT /api/v1/urls/:id Update an existing short URL (requires token)
DELETE /api/v1/urls/:id Delete a short URL (requires token)

Analytics Routes

Method Endpoint Description
GET /api/v1/analytics Fetch global analytics (requires token)
GET /api/v1/analytics/:id Fetch analytics for a specific URL (requires token)

Installation and Setup

  1. Clone the repository: git clone https://github.com/zdev2/shortlink.git
  2. Navigate to the directory: cd shortlink
  3. Install dependencies: go mod tidy
  4. Create a .env file with the necessary environment variables.
  5. Run the application: go run main.go
  6. Access the application at http://localhost:3000

Conclusion

The URL Shortener application provides all the tools necessary to shorten, manage, and analyze URLs effectively. It is fast, secure, and scalable, making it ideal for modern web applications.