This is a simple URL Shortener built with .NET 8 and Entity Framework Core (EF Core). The application allows users to shorten URLs via a single-page web interface and stores the mappings in an SQLite database.
- Shorten URLs and generate unique short codes.
- Redirect from short codes to the original URLs.
- Persistent storage using SQLite.
- Simple SPA frontend using Pico.css.
- .NET 8 SDK (Download here)
- SQLite (installed with .NET dependencies, no manual installation required)
git clone https://github.com/rleer/url-shortener.git
cd url-shortener/src/UrlShortener.API
Ensure you have all required .NET dependencies:
dotnet restore
This will create an urls.db
SQLite database and apply the necessary schema:
dotnet ef migrations add InitialCreate
dotnet ef database update
Start the API service:
dotnet run
The application will be accessible at:
http://localhost:5062/
POST /shorten
{
"url": "https://example.com"
}
Response:
{
"shortenedUrl": "http://localhost:5000/abc123"
}
GET /{shortCode}
- Redirects the user to the stored original URL.
- Returns
404 Not Found
if the code is not found in the database.
- .NET 8 (Minimal API)
- Entity Framework Core (SQLite database)
- Pico.css (Lightweight CSS framework)
- JavaScript Fetch API (Frontend AJAX calls)
- If you encounter issues with the database, try deleting
urls.db
and rerunning migrations:rm urls.db dotnet ef database update
- The frontend automatically updates the page with the shortened URL without refreshing.
- Implement more sophisticated URL shortening algorithm
- Implement URL validation and sanitization
- Improve error handling
- Implement analytics (click tracking)
- Add user authentication for managing links
- Use a cloud database instead of SQLite
Now you can run and test the URL shortener! 🚀