Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit a2f04b7

Browse files
authored
Merge pull request #11 from nodes-vapor/feature/describe-rate-limit
Updated README to use correct class names.
2 parents a0e7b2a + d764357 commit a2f04b7

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
[![Readme Score](http://readme-score-api.herokuapp.com/score.svg?url=https://github.com/nodes-vapor/gatekeeper)](http://clayallsopp.github.io/readme-score?url=https://github.com/nodes-vapor/gatekeeper)
99
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nodes-vapor/gatekeeper/master/LICENSE)
1010

11-
Rate Limiter middleware.
11+
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**
1215

1316

1417
## 📦 Installation
@@ -21,12 +24,55 @@ Update your `Package.swift` file.
2124

2225
## Getting started 🚀
2326

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.
2535

36+
#### Adding Middleware Globally
37+
38+
#### `Sources/App/Config+Setup.swift`
2639
```swift
27-
let limiter = RateLimiter(rate: Rate(10, per: .minute))
40+
import Gatekeeper
41+
```
42+
43+
```swift
44+
public func setup() throws {
45+
// ...
46+
47+
addConfigurable(middleware: GateKeeper(rate: Rate(10, per: .minute)), name: "gatekeeper")
48+
}
2849
```
2950

51+
#### `Config/droplet.json`
52+
53+
Add `gatekeeper` to the middleware array
54+
55+
```json
56+
"middleware": [
57+
"error",
58+
"date",
59+
"file",
60+
"gatekeeper"
61+
]
62+
```
63+
64+
65+
#### Adding Middleware to a Route Group
66+
67+
```Swift
68+
let gatekeeper = Gatekeeper(rate: Rate(10, per: .minute))
69+
70+
drop.group(gatekeeper) { group in
71+
// Routes
72+
}
73+
```
74+
75+
3076
### The `Rate.Interval` enumeration
3177

3278
The currently implemented intervals are:

0 commit comments

Comments
 (0)