RUST Essentials Intermediate

URL Shortening Service in Rust

Develop a minimalist URL shortening microservice using the Axum framework and its routing system.

Premium · 2h 58m · 4 ch
Practice →
URL Shortening Service in Rust cover

What you'll build

We will create a full-fledged URL shortening service from scratch using Rust and the axum web framework. Starting with a bare Cargo project, we will gradually add support for an asynchronous runtime, HTTP routing, CLI configuration, request handlers, shared state management, and a domain-specific code type with base62 encoding.

Along the way, we will see how axum's extractor system works, how to safely share mutable state between asynchronous handlers using Arc<RwLock<T>>, and how to implement custom Serde serialization for domain-specific types. By the end, our service will accept URLs through a POST endpoint, generate compact short codes, store mappings in memory, and redirect visitors back to the original destination.

Learning objectives

✓Set up an asynchronous Rust web service with axum and tokio
✓Configure runtime parameters using clap and environment variables
✓Implement REST endpoints for creating links and redirecting
✓Manage shared mutable state using Arc<RwLock>
✓Design a domain-specific type with custom Display and Deserialize implementations
✓Build an in-memory storage model with bidirectional lookup in HashMap

Prerequisites

▸Basic Rust syntax (structures, enumerations, traits, modules)
▸Familiarity with async/await in Rust
▸Basic understanding of HTTP methods and status codes

Course curriculum

1 Configurable HTTP Service
—Initial Server Setup
—Adding Parameters for Address Configuration
—Adding the index handler
2 Link Codes and State
—Representing the Short Code as an Index
—Encoding a Numeric Identifier in Base62
—Decoding the Short Code from the URL
—Implementing the URL Shortener State
—Implementing the State Constructor
3 URL Lookup and Registration
—Retrieving the Stored Address by Short Code
—Registering the Original Address
—Generating a Unique Short Code
—Building a Short Link
—Reissuing short links
4 URL Shortening Service
—Configuring the service host address
—Connecting Shared State to Routing
—Implementing the short link creation handler
—Implementing the Redirect 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 work through the project step by step in your browser, and the reference code for each step saves to your disk — yours to run and keep locally.

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.

Newsletter

New playgrounds in your inbox

Get an email when a new playground drops, plus the occasional engineering deep-dive. No spam, unsubscribe anytime.