Skip to content

Potato-29/url-shortener-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started

Prerequisites

  • Go (version 1.16 or later)
  • MongoDB (for storing URLs)

Installation

  1. Clone the repository:

    git clone https://github.com/Potato-29/url-shortener.git
    cd url-shortener
  2. Install the required Go packages:

    go mod tidy
  3. Set up your MongoDB instance and update the connection URI in the code.

Running the Application

  1. Start the MongoDB server.

  2. Run the application:

    go run internal/api/main.go
  3. Open your browser and navigate to http://localhost:8080 to access the URL shortener.

API Endpoints

Home Page

  • GET /: Renders the home page where users can input URLs to shorten.

URL Shortening

  • POST /api/shorten: Accepts a long URL and an optional alias to create a shortened URL.

    • Request Body:
      {
        "base-url": "https://example.com",
        "alias": "custom-alias"
      }
  • GET /:id: Redirects to the original URL based on the shortened ID.

URL Management

  • PUT /api/shorten/:id: Updates the base URL for a given shortened ID.

    • Request Body:
      {
        "base-url": "https://new-url.com"
      }
  • DELETE /api/shorten/:id: Deletes the shortened URL entry.

Statistics

  • GET /api/stats/:id: Retrieves the access count for the shortened URL.

Project Info

This is a project I started from roadmaps.sh

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published