Link Shortener Service in Rust

Develop a minimalistic link-shortening microservice using the Axum framework and its routing system.

Link Shortener Service in Rust cover

What You'll Build

We'll build a complete URL shortening service from scratch using Rust and the axum web framework. Starting with a bare Cargo project, we'll progressively add async runtime support, HTTP routing, CLI configuration, request handlers, shared state management, and a domain-specific code type with base62 encoding.

Along the way we'll see how axum's extractor system works, how to share mutable state safely across async handlers using Arc<RwLock<T>>, and how to implement custom Serde serialization for domain types. By the end, our service accepts URLs via a POST endpoint, generates compact short codes, stores mappings in memory, and redirects visitors back to the original destination.

Learning Objectives

  • Set up an async Rust web service with axum and tokio

  • Configure runtime options with clap and environment variables

  • Implement REST endpoints for link creation and redirection

  • Manage shared mutable state with Arc<RwLock>

  • Design a domain type with custom Display and Deserialize implementations

  • Build an in-memory storage model with bidirectional HashMap lookups

Prerequisites

  • Basic Rust syntax (structs, enums, traits, modules)

  • Familiarity with async/await in Rust

  • Basic understanding of HTTP methods and status codes

Course curriculum

1 Configurable HTTP Service

  • Bootstrapping a server
  • Add options to configure address
  • Add the index handler

2 Link Codes And State

  • Implement the Code struct
  • Converting Code to a string
  • Deserialize the code
  • Implement the Shortener state
  • Add the new method to the state

3 URL Lookup and Registration

  • Implement the lookup method
  • Implement the register method
  • Generate the unique Code value
  • Construct a short link
  • Avoid link duplications

4 URL Shortening Service

  • Add the state to the Router
  • Implement the create_link handler
  • Code collision
  • Implement the follow_link handler
  • Testing the shortener

Technologies

Rust axum URL Shortener Microservice REST API tokio Shared State Base62 Serde clap

FAQ

Is this a video course?

No. You implement the project yourself, step by step, right in your browser — with a full reference solution for every step when you get stuck.

Do I need to install anything?

No. The playground runs entirely in your browser — no toolchain or local setup required.

Can I try it before subscribing?

Yes. Preview steps are available without a subscription so you can see the format and quality first.

What do I get with full access?

Every step unlocked, the Workbench app, a snapshot for each step, jump-to-any-step navigation, and all new playground releases.

Does it work with an AI agent like Claude or Codex?

Yes. You can work through a playground solo or alongside an AI agent.

Is there reference code?

Yes. Every step has a complete reference solution you can compare against.