25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

TutorialEdge Project

Building an API Gateway in Rust

In this project series, we are going to be building a fully functional API gateway from scratch in Rust! We'll cover routing, middleware, rate limiting, load balancing, and more.

rust
Start Project 🚀
Elliot Forbes with Elliot Forbes

API gateways sit at the front door of your backend services. They handle incoming requests and route them to the right place, while taking care of cross-cutting concerns like authentication, rate limiting, and logging so your individual services don’t have to.

Building one from scratch is an incredible way to learn Rust. You’ll work with async networking, trait-based abstractions, concurrent data structures, and real-world patterns that come up in production systems every day.

What We’re Building

Over the course of this series, we’ll build a fully functional API gateway called Ferroway that can:

  • Accept incoming HTTP requests and proxy them to backend services
  • Match requests to the right upstream service based on path rules
  • Run a pipeline of middleware (logging, CORS headers, custom headers)
  • Rate limit clients to protect your backend from abuse
  • Load balance across multiple instances of the same service with health checks
  • Read its configuration from a YAML file and support JWT authentication

Prerequisites

This series is designed to be beginner-friendly. You should have:

  • Rust installed on your machine (we’ll be using the latest stable release)
  • A basic understanding of what variables, functions, and structs are in Rust
  • Some familiarity with the command line

We’ll explain Rust-specific concepts like ownership, borrowing, traits, and async/await as they come up naturally in the code. You don’t need to be a Rust expert to follow along!

Series Outline

  1. Project Setup & Your First HTTP Proxy - We’ll set up the project, learn about Tokio for async Rust, and build a working reverse proxy that forwards requests to a backend server.

  2. Routing & Path Matching - We’ll add a routing layer so our gateway can send requests to different backend services based on the URL path.

  3. Middleware Pipeline - We’ll build a composable middleware system using Rust traits, then implement logging, CORS, and custom header injection.

  4. Rate Limiting - We’ll protect our backend services by implementing a token bucket rate limiter that tracks requests per client IP.

  5. Load Balancing & Health Checks - We’ll distribute traffic across multiple instances of the same service and automatically stop routing to unhealthy backends.

  6. Configuration & Authentication - We’ll move our gateway config into a YAML file and add JWT-based authentication middleware.

Project Parts

  1. 1 Part 1 - Project Setup & Your First HTTP Proxy Set up a Rust project, learn async basics with Tokio, and build a working reverse proxy that forwards HTTP requests to a backend.
  2. 2 Part 2 - Routing & Path Matching Add a routing layer to your Rust API gateway so it forwards requests to different backend services based on URL path patterns.
  3. 3 Part 3 - Middleware Pipeline Build a composable middleware system in Rust using traits, implementing logging, CORS, and custom header injection for your API gateway.
  4. 4 Part 4 - Rate Limiting Implement a token bucket rate limiter as middleware for your Rust API gateway, protecting backends by tracking requests per client IP.
  5. 5 Part 5 - Load Balancing & Health Checks Add round-robin load balancing to your Rust API gateway, with background health checks that automatically remove unhealthy backends.
  6. 6 Part 6 - Configuration & Authentication Move your Rust API gateway config into YAML and add JWT-based authentication middleware to protect your backend services.