A simple and efficient URL shortener service built with ASP.NET Core 10, featuring a web UI and a REST API. It uses SQLite for storage and Sqids for generating short, unique identifiers.
- URL Shortening: Create short links for long URLs.
- Custom Expiry: Set expiration dates for shortened links.
- Automatic Cleanup: A background worker automatically removes expired links every 24 hours.
- REST API: Minimal API endpoint for programmatic URL shortening.
- Web UI: User-friendly Razor Pages interface for manual shortening.
- OpenAPI Support: Integrated Swagger/OpenAPI documentation (available in development).
- Validation: Robust request validation using FluentValidation.
- Framework: ASP.NET Core 10 (Razor Pages & Minimal APIs)
- Database: SQLite (Entity Framework Core)
- URL Encoding: Sqids
- Validation: FluentValidation
- API Documentation: Microsoft.AspNetCore.OpenApi
-
Clone the repository:
git clone https://github.com/your-username/UrlShortener.git cd UrlShortener -
Run the project:
dotnet run --project UrlShortener
-
Open your browser and navigate to
https://localhost:5001(or the port specified in the output).
- Endpoint:
POST /api/create - Request Body:
{ "fullUri": "https://www.example.com/very-long-url", "expiresAt": "2026-12-31T23:59:59Z" } - Response:
{ "shortenedUrl": "abc123" }
- Endpoint:
GET /{sqid} - Description: Redirects to the original URL associated with the provided
sqid.
UrlShortener/Presentation: Contains API endpoints and models.UrlShortener/Infrastructure: Database context and entity models.UrlShortener/Services: Business logic, includingSqidService.UrlShortener/Workers: Background tasks likeCleanupWorker.UrlShortener/Pages: Razor Pages for the web UI.UrlShortener/Validations: FluentValidation validators.
The application uses SQLite. The database file urlshortener.sqlite is automatically created on the first run.
This project is licensed under the MIT License.