···55The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
667788+## [Unreleased]
99+1010+### Changed
1111+1212+- Removed the need for `glimit.build()` and `glimit.try_build()` functions. Now, the `glimit.apply()` function can be used directly with the limiter configuration.
1313+1414+815## 0.2.0 - 2024-09-07
9161017### Breaking changes
···1623- Added a `burst_limit` setting to the limiter configuration. This setting allows the user to set the maximum number of tokens that the bucket can hold.
172418251919-## v0.1.3 - 2024-09-04
2626+## 0.1.3 - 2024-09-04
20272128### Added
2229
···2323 let body = string_builder.from_string("<h1>Too many requests</h1>")
2424 wisp.html_response(body, 429)
2525 })
2626- |> glimit.build
27262827 wisp.configure_logger()
2928
+29-15
src/glimit.gleam
···2929//// |> glimit.burst_limit(100)
3030//// |> glimit.identifier(fn(request) { request.ip })
3131//// |> glimit.on_limit_exceeded(fn(_request) { "Rate limit reached" })
3232-//// |> glimit.build()
3332////
3433//// let handler =
3534//// fn(_request) { "Hello, world!" }
···119118120119/// Build the rate limiter.
121120///
122122-/// Panics if the rate limiter registry cannot be started or if the `identifier`
123123-/// function or `on_limit_exceeded` function is missing.
121121+/// Note that using `apply` will already build the rate limiter, so this function is
122122+/// only useful if you want to build the rate limiter manually and apply it to multiple
123123+/// functions.
124124///
125125-/// To handle errors instead of panicking, use `try_build`.
125125+/// To apply the resulting rate limiter to a function or handler, use the `apply_built`
126126+/// function.
126127///
127127-pub fn build(config: RateLimiterBuilder(a, b, id)) -> RateLimiter(a, b, id) {
128128- case try_build(config) {
129129- Ok(limiter) -> limiter
130130- Error(message) -> panic as message
131131- }
132132-}
133133-134134-/// Build the rate limiter, but return an error instead of panicking.
135135-///
136136-pub fn try_build(
128128+pub fn build(
137129 config: RateLimiterBuilder(a, b, id),
138130) -> Result(RateLimiter(a, b, id), String) {
139131 use per_second <- result.try(case config.per_second {
···166158167159/// Apply the rate limiter to a request handler or function.
168160///
169169-pub fn apply(func: fn(a) -> b, limiter: RateLimiter(a, b, id)) -> fn(a) -> b {
161161+/// Panics if the rate limiter registry cannot be started or if the `identifier`
162162+/// function or `on_limit_exceeded` function is missing.
163163+///
164164+pub fn apply(
165165+ func: fn(a) -> b,
166166+ config: RateLimiterBuilder(a, b, id),
167167+) -> fn(a) -> b {
168168+ let limiter = case build(config) {
169169+ Ok(limiter) -> limiter
170170+ Error(message) -> panic as message
171171+ }
172172+ apply_built(func, limiter)
173173+}
174174+175175+/// Apply the rate limiter to a request handler or function.
176176+///
177177+/// This function is useful if you want to build the rate limiter manually using the
178178+/// `build` function.
179179+///
180180+pub fn apply_built(
181181+ func: fn(a) -> b,
182182+ limiter: RateLimiter(a, b, id),
183183+) -> fn(a) -> b {
170184 fn(input: a) -> b {
171185 let identifier = limiter.identifier(input)
172186 case limiter.rate_limiter_registry |> registry.get_or_create(identifier) {