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.
You can try out the URL shortener at the following link:
- 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
- Visit the URL Shortener App.
- Enter a long URL in the input field.
- Click on the "Shorten" button.
- The shortened URL will be displayed below the input field.
- Go 1.16+
- MongoDB 4.4+
- A running MongoDB instance
git clone https://github.com/your-username/url-shortener.git
cd url-shortener
go mod tidy
brew tap mongodb/brew
brew install mongodb-community@6.0
brew services start mongodb/brew/mongodb-community@6.0
export MONGODB_URI="your-mongodb-uri"
go build -o bin/url-shortener main.go
./bin/url-shortener
heroku create your-app-name
heroku addons:create mongolab:sandbox
heroku config:set MONGODB_URI="your-mongodb-uri"
git add .
git commit -m "your message"
git push heroku main
-
URL:
/api/shorten
-
Method:
POST
-
Request Body:
{ "url": "https://www.example.com" }
-
Response:
{ "short_url": "http://short.url/abc123" }
-
URL:
/api/{shortURL}
-
Method:
GET
-
Response:
{ "original_url": "http://www.example.com" }
-
URL:
/api/check
-
Method:
POST
-
Request Body:
{ "url": "https://www.example.com" }
-
Response:
{ "exists": "true" "short_url": "https://www.example.com", "expired": "true/false" }
-
URL:
/api/urls
-
Method:
POST
-
Request Body:
[ { "short_url": "abc123", "original_url": "https://www.example.com", "expiration": "date-time" } ]
-
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
).
- Allow users to specify custom aliases for their shortened URLs (e.g.,