- Go (version 1.16 or later)
- MongoDB (for storing URLs)
-
Clone the repository:
git clone https://github.com/Potato-29/url-shortener.git cd url-shortener -
Install the required Go packages:
go mod tidy
-
Set up your MongoDB instance and update the connection URI in the code.
-
Start the MongoDB server.
-
Run the application:
go run internal/api/main.go
-
Open your browser and navigate to
http://localhost:8080to access the URL shortener.
- GET /: Renders the home page where users can input URLs to shorten.
-
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" }
- Request Body:
-
GET /:id: Redirects to the original URL based on the shortened ID.
-
PUT /api/shorten/:id: Updates the base URL for a given shortened ID.
- Request Body:
{ "base-url": "https://new-url.com" }
- Request Body:
-
DELETE /api/shorten/:id: Deletes the shortened URL entry.
- GET /api/stats/:id: Retrieves the access count for the shortened URL.
This is a project I started from roadmaps.sh