You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 20, 2024. It is now read-only.
GateKeeper is a middleware that restricts the number of requests from clients, based on their IP address.
12
+
It works by adding the clients IP address to the cache and count how many requests the clients can make during the GateKeepers defined lifespan and give back an HTTP 429(Too Many Requests) if the limit has been reached. The number of requests left will be reset when the defined timespan has been reached
13
+
14
+
**Please take into consideration that multiple clients can be using the same IP address. eg. public wifi**
12
15
13
16
14
17
## 📦 Installation
@@ -21,12 +24,55 @@ Update your `Package.swift` file.
21
24
22
25
## Getting started 🚀
23
26
24
-
`RateLimiter` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache.
27
+
`Gatekeeper` has two configurable fields: the maximum rate and the cache to use. If you don't supply your own cache the limiter will create its own, in-memory cache.
28
+
29
+
```swift
30
+
let gatekeeper =GateKeeper(rate: Rate(10, per: .minute))
31
+
```
32
+
33
+
### Adding middleware
34
+
You can add the middleware either globally or to a route group.
25
35
36
+
#### Adding Middleware Globally
37
+
38
+
#### `Sources/App/Config+Setup.swift`
26
39
```swift
27
-
let limiter =RateLimiter(rate: Rate(10, per: .minute))
0 commit comments