How to add rate limiting in Ruby on Rails 8 ruby

How to add rate limiting in Ruby on Rails 8

Rate limiting in Rails 8 is built in: the rate_limit method declares limits per controller and action, like 3 requests per 2 seconds on create. How to combine short and long windows, protect unsafe actions, and practical suggestions for sensible limits.

Jan 6, 2025

Powerful switch statement with pattern matching in Ruby

Powerful switch statement with pattern matching in Ruby

Pattern matching in Ruby turns case statements into a precise switch over data shapes: match and destructure hashes from an API response, combine several patterns in one branch, capture values across patterns, and validate configuration. Ruby 2.7+ syntax examples.

How to set up XML in Grape API

How to set up XML in Grape API

XML support in Grape API takes two steps: register the additional content_type so endpoints accept and return application/xml, then change the root element name of the XML output. Complete Ruby examples built around a products endpoint you can adapt to your API.