documentation/dsls/DSL-AshRateLimiter.md

<!--
This file was generated by Spark. Do not edit it by hand.
-->
# AshRateLimiter

An extension for `Ash.Resource` which adds the ability to rate limit access to actions.


## rate_limit
Configure rate limiting for actions.

#### Hammer

This library uses the [hammer](https://hex.pm/packages/hammer) package to provide
rate limiting features.  See [hammer's documentation](https://hexdocs.pm/hammer) for more information.

#### Keys

Hammer uses a "key" to identify which bucket to allocate an event against.  You can use this to tune the rate limit for specific users or events.

You can provide either a statically configured string key, or a function of arity one or two, which when given a query/changeset and optional context object can generate a key.

The default is `AshRateLimiter.key_for_action/2`. See it's docs for more information.


### Nested DSLs
 * [action](#rate_limit-action)


### Examples
```
rate_limit do
  action :create, limit: 10, per: :timer.minutes(5)
end

```




### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`hammer`](#rate_limit-hammer){: #rate_limit-hammer .spark-required} | `module` |  | The hammer module to use for rate limiting |



### rate_limit.action
```elixir
action action
```


Configure rate limiting for a single action.

It does this by adding a global change or preparation to the resource with the provided configuration.  For more advanced configuration you can add the change/preparation directly to your action using `AshRateLimiter.BuiltinChanges.rate_limit/1` or `AshRateLimiter.BuiltinPreparations.rate_limit/1`.






### Arguments

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`action`](#rate_limit-action-action){: #rate_limit-action-action .spark-required} | `atom` |  | The name of the action to limit |
### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`limit`](#rate_limit-action-limit){: #rate_limit-action-limit .spark-required} | `pos_integer` |  | The maximum number of events allowed within the given period |
| [`per`](#rate_limit-action-per){: #rate_limit-action-per .spark-required} | `pos_integer` |  | The time period (in milliseconds) for in which events are counted |
| [`key`](#rate_limit-action-key){: #rate_limit-action-key } | `String.t \| (any -> any) \| (any, any -> any)` | `&AshRateLimiter.key_for_action/2` | The key used to identify the event. See above. |
| [`description`](#rate_limit-action-description){: #rate_limit-action-description } | `String.t` |  | A description of the rate limit |





### Introspection

Target: `AshRateLimiter`





<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>