recipes icon indicating copy to clipboard operation
recipes copied to clipboard

feat: add rate limiter middleware recipe using Redis

Open vedant-colab opened this issue 5 months ago • 2 comments

What this PR does

Adds a new recipe for implementing a rate limiter middleware in Fiber using Redis.
The middleware limits incoming requests based on client IP and a fixed time window.

Features

  • Redis-backed rate limiting
  • Configurable time window and request cap
  • Adds Retry-After header for better client UX
  • Returns 429 Too Many Requests when limit exceeded

Why it's useful

This recipe shows developers how to:

  • Integrate Redis with Go Fiber
  • Use Fiber middleware pattern
  • Handle rate limiting cleanly and idiomatically
  • Improve API reliability under load

Folder Structure

rate-limit-redis/ ├── config/ │ └── redis.go ├── handlers/ │ └── home.go ├── middleware/ │ └── limiter.go ├── main.go

How to Run

  1. Start Redis locally or via Docker: docker run -p 6379:6379 redis

2.Run the project: go run main.go

3.Test with: curl http://localhost:8080/home

Summary by CodeRabbit

  • New Features
    • Introduced a rate limiting middleware for the Fiber web framework using Redis to restrict the number of requests per IP address.
    • Added a sample endpoint to demonstrate rate-limited access.
  • Documentation
    • Added comprehensive documentation with setup instructions, usage examples, and configuration guidelines for the rate limiter.

vedant-colab avatar Jun 12 '25 16:06 vedant-colab