From a07c65054b87143998f691853c3fed5a38b5901c Mon Sep 17 00:00:00 2001 From: Ed Robinson Date: Mon, 3 Jun 2024 11:59:02 +0100 Subject: [PATCH] Add usage example to README --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 93299bb..60aae43 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,28 @@ # Millrace +## Usage + +``` +class UsersController + + before_action Millrace::RateLimit.new( + name: "follows", + rate: 1/60.0, # 1 request per minute + window: 1.minute, + penalty: 10.minutes, + ), only: :create + + rescue_from Millrace::RateLimited do |error| + # perhaps record metrics here + response.set_header "Retry-After", error.retry_after + head :too_many_requests + end + +... + +end +``` + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/millrace. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/millrace/blob/main/CODE_OF_CONDUCT.md).