A modern, high-performance link shortener service built using the latest features of .NET 10 and ASP.NET Core 10. This project serves as a practical example of building lightweight, secure, and efficient web APIs with Minimal APIs, EF Core, and ASP.NET Core Identity.
- URL Shortening: Convert long URLs into unique, short codes.
- Redirection & Tracking: Redirects short links to their original destination and increments a view counter.
- User-Specific Links: Securely manage links on a per-user basis using JWT authentication.
- Paginated Link Listing: Efficiently retrieve a user's created links with pagination.
- Validation: Robust request validation using FluentValidation.
- API Documentation: Interactive API documentation powered by Swagger (OpenAPI).
- .NET 10: The core platform, utilizing the latest performance improvements and language features.
- ASP.NET Core 10:
- Minimal APIs: For creating concise, high-performance HTTP endpoints.
- ASP.NET Core Identity: For handling user registration, login, and JWT-based authentication.
- Entity Framework Core 10: For data access, using an in-memory database for this example.
- FluentValidation: A modern library for building strongly-typed validation rules.
- Swagger (OpenAPI): For generating beautiful and interactive API documentation.
- .NET 10 SDK (or a newer preview version).
- A REST client like Postman or the
dotnet-httprepl
tool.
-
Clone the repository:
git clone https://github.com/your-username/LinkShortener.git cd LinkShortener
-
Run the project:
dotnet run --project LinkShortener/LinkShortener.csproj
-
Access the API documentation: The application will start, and you can access the Swagger UI to explore and test the endpoints at:
http://localhost:<port>/swagger
(e.g.,http://localhost:5123/swagger
)
The API is secured with JWT. You must first register a user and log in to get a bearer token. Add this token to the Authorization
header for protected endpoints (e.g., Authorization: Bearer <your_token>
).
Method | Path | Description | Auth Required |
---|---|---|---|
POST |
/register |
Creates a new user account. | No |
POST |
/login |
Authenticates a user and returns a JWT. | No |
POST |
/links |
Creates a new shortened link for the current user. | Yes |
GET |
/links/{shortUrl} |
Redirects to the original URL. | No |
GET |
/links |
Gets a paginated list of the user's links. | Yes |
GET |
/links/info/{id} |
Gets detailed information about a specific link. | Yes |
This project demonstrates several modern .NET best practices:
- Minimal APIs: Endpoints are defined concisely in
LinkEndpoints.cs
, promoting a clean and functional approach. - Global Exception Handling: A custom
IExceptionHandler
(GlobalExceptionHandler.cs
) is implemented to centralize error handling and provide consistent JSON error responses. - Endpoint Filters: The
ValidationFilter.cs
acts as an AOP (Aspect-Oriented Programming) component, intercepting requests to validate them before the endpoint handler is executed. This keeps the endpoint logic clean and focused. - Service Layer Abstraction: Business logic is encapsulated within services (
ILinkService
) which are injected via Dependency Injection, promoting testability and separation of concerns. - Modern C# Features: The project uses
record
types for immutable DTOs and primary constructors for cleaner class definitions.
This project is licensed under the MIT License. See the LICENSE file for details.