Skip to content

A URL shortener service built with Go, MongoDB, and Gorilla Mux. Shorten, manage, and retrieve URLs efficiently with this API.

License

Notifications You must be signed in to change notification settings

joymohanty8999/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A URL shortener service built with Go, MongoDB, and Gorilla Mux. This service shortens long URLs and provides an API to retrieve the original URL and check the expiration status of the shortened URL. Along with these three features, the user can also request all the URLs generated by them.

Live Demo

You can try out the URL shortener at the following link:

URL Shortener App

Features

  • Shorten a long URL
  • Retrieve the original URL from the shortened URL
  • Check if a URL is stored in the database and if it is expired
  • Store URLs in a MongoDB database with an expiration time

Usage

  1. Visit the URL Shortener App.
  2. Enter a long URL in the input field.
  3. Click on the "Shorten" button.
  4. The shortened URL will be displayed below the input field.

Prerequisites

  • Go 1.16+
  • MongoDB 4.4+
  • A running MongoDB instance

Installation

1. Clone the repository

git clone https://github.com/your-username/url-shortener.git
cd url-shortener

2. Install GO Dependencies

go mod tidy

Install and start MongoDB

macOS

1. Add the MongoDB Homebrew tap:
brew tap mongodb/brew
2. Install MongoDB Community Edition:
brew install mongodb-community@6.0
3. Start the MongoDB service:
brew services start mongodb/brew/mongodb-community@6.0

Running the application

1. Ensure MongoDB is running

2. Set your environment variables

export MONGODB_URI="your-mongodb-uri"

3. Build and start the GO Server

go build -o bin/url-shortener main.go
./bin/url-shortener

Deploying to Heroku

1. Create a Heroku App:

heroku create your-app-name

2. Add MongoDB Add-on

heroku addons:create mongolab:sandbox

3. Set environment variables

heroku config:set MONGODB_URI="your-mongodb-uri"

4. Deploy to Heroku

git add .
git commit -m "your message"
git push heroku main

API Endpoints

Shorten URL

  • URL: /api/shorten

  • Method: POST

  • Request Body:

    {
      "url": "https://www.example.com"
    }
  • Response:

    {
        "short_url": "http://short.url/abc123"
    }

Shorten Image

Retrieve URL

  • URL: /api/{shortURL}

  • Method: GET

  • Response:

    {
        "original_url": "http://www.example.com"
    }

Retrieve Image

Check validity of URL

  • URL: /api/check

  • Method: POST

  • Request Body:

    {
      "url": "https://www.example.com"
    }
  • Response:

    {
        "exists": "true"
        "short_url": "https://www.example.com",
        "expired": "true/false"
    }

Check Validity

Get All generated short URLs

  • URL: /api/urls

  • Method: POST

  • Request Body:

    [
        {
            "short_url": "abc123",
            "original_url": "https://www.example.com",
            "expiration": "date-time"
        }
    ]

Get All URLs

Future Scope and Improvements

  • User Authentication:

    • Implement user authentication to allow users to create accounts and log in.
    • Use OAuth providers (e.g., Google, Facebook) for easy login.
  • User-Specific URLs:

    • Allow users to manage their own set of shortened URLs.
    • Provide a dashboard where users can view, edit, and delete their URLs.
  • Custom Short URLs:

    • Allow users to specify custom aliases for their shortened URLs (e.g., https://short.url/customAlias).

About

A URL shortener service built with Go, MongoDB, and Gorilla Mux. Shorten, manage, and retrieve URLs efficiently with this API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published