Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

C#intermediatebackendAI generated

URL Shortener API with Minimal APIs

Build a URL shortener service with ASP.NET Core Minimal APIs and Entity Framework Core. You send it a long link and get back a short one, like http://localhost:5000/aB3xK9; anyone opening the short link is redirected to the original, and every click is counted. An analytics endpoint shows how many clicks a link got and when it was created, and the create endpoint is rate limited so one user can't flood it. Links are stored in SQLite. You'll learn Minimal API routing and results, EF Core with SQLite and migrations, generating short codes that don't collide, validating URLs, redirects, and ASP.NET Core's built-in rate limiting.

Estimate
~9.5h
Steps
6
Completed by
0
Proposed by
codeseed.app

ASP.NET Core Minimal APIs · Entity Framework Core · SQLite

Project roadmap

  1. 01

    Create the project and model

    ~1.5h

    Create a project with dotnet new web and add EF Core with the SQLite provider. Define a ShortLink entity (Id, Code with a unique index, OriginalUrl, CreatedAt, ClickCount) and an AppDbContext. Create and apply the first migration. Done when: the database file is created with the ShortLinks table.

  2. 02

    Create short links

    ~2h

    Add POST /api/links accepting { "url": "..." }. Check the URL is absolute http or https with Uri.TryCreate and at most 2,048 characters. Generate a random 7-character code from letters and digits using RandomNumberGenerator, and try again when the code already exists. Return 201 with the code and the full short URL. Done when: posting a valid URL returns a short link, and an invalid one returns 400.

  3. 03

    Redirect and count clicks

    ~1.5h

    Add GET /{code}: look up the link, increase ClickCount with a single UPDATE (ExecuteUpdateAsync) so simultaneous clicks aren't lost, and return a 302 redirect to the original URL. Return 404 for unknown codes. Done when: opening a short link in the browser lands on the original page, and the click count increases.

  4. 04

    Add analytics

    ~1h

    Add GET /api/links/{code}/stats returning the original URL, the creation date and the click count. Use Minimal API route groups (MapGroup) to organize the /api endpoints, and TypedResults for the responses. Done when: the stats endpoint shows the correct click count after several visits.

  5. 05

    Rate limit link creation

    ~1.5h

    Add ASP.NET Core rate limiting with AddRateLimiter: a fixed-window policy partitioned by the client's IP address, allowing for example 10 new links per minute, applied only to the POST endpoint with RequireRateLimiting. Return 429 with a Retry-After header when the limit is exceeded. Done when: the 11th request within a minute gets 429, and redirects are never limited.

  6. 06

    Write integration tests

    ~2h

    Create an xUnit project using WebApplicationFactory with a SQLite in-memory database. Test creating a link, the redirect (disable automatic redirects in the test client to check the 302 and Location header), click counting, stats, unknown codes, invalid URLs and rate limiting. Done when: dotnet test passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~9.5h · 6 steps

Tech stack

ASP.NET Core Minimal APIsEntity Framework CoreSQLite