Skip to content

tborozan/url_shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UrlShortener

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.

Features

  • 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.

Tech Stack

  • Framework: ASP.NET Core 10 (Razor Pages & Minimal APIs)
  • Database: SQLite (Entity Framework Core)
  • URL Encoding: Sqids
  • Validation: FluentValidation
  • API Documentation: Microsoft.AspNetCore.OpenApi

Getting Started

Prerequisites

Running the Application

  1. Clone the repository:

    git clone https://github.com/your-username/UrlShortener.git
    cd UrlShortener
  2. Run the project:

    dotnet run --project UrlShortener
  3. Open your browser and navigate to https://localhost:5001 (or the port specified in the output).

API Usage

Create a Shortened URL

  • Endpoint: POST /api/create
  • Request Body:
    {
      "fullUri": "https://www.example.com/very-long-url",
      "expiresAt": "2026-12-31T23:59:59Z"
    }
  • Response:
    {
      "shortenedUrl": "abc123"
    }

Redirect

  • Endpoint: GET /{sqid}
  • Description: Redirects to the original URL associated with the provided sqid.

Project Structure

  • UrlShortener/Presentation: Contains API endpoints and models.
  • UrlShortener/Infrastructure: Database context and entity models.
  • UrlShortener/Services: Business logic, including SqidService.
  • UrlShortener/Workers: Background tasks like CleanupWorker.
  • UrlShortener/Pages: Razor Pages for the web UI.
  • UrlShortener/Validations: FluentValidation validators.

Database

The application uses SQLite. The database file urlshortener.sqlite is automatically created on the first run.

License

This project is licensed under the MIT License.

About

Simple URL shortener

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors