Skip to content

Commit 20badcd

Browse files
committed
improve code sample
1 parent 56d8afa commit 20badcd

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

utilities/rate-limit/index.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,30 +202,29 @@ container.add(
202202
.requestIdentifier(TSessionRequestIdentifier.create())
203203
);
204204
```
205-
For `TQueryParamRequestIdentifier`
205+
`requestIdentifier()` returns current factory instance so that you can chain with other methods,
206206

207207
```
208208
container.add(
209209
'throttle-one-request-per-sec',
210210
TThrottleMiddlewareFactory.create()
211-
.requestIdentifier(TQueryParamRequestIdentifier.create('my-key'))
211+
.requestIdentifier(TSessionRequestIdentifier.create())
212+
.ratePerSecond(1)
212213
);
213214
```
214-
where `my-key` is query parameter key used to identify. So
215-
`http://myapp.fano?my-key=1` and `http://myapp.fano?my-key=2` will be identified as separate request.
216-
217-
`requestIdentifier()` returns current factory instance so that you can chain with other methods,
215+
`TQueryParamRequestIdentifier` class constructor requires one parameter, name of query string key.
218216

219217
```
220218
container.add(
221219
'throttle-one-request-per-sec',
222220
TThrottleMiddlewareFactory.create()
223-
.requestIdentifier(TSessionRequestIdentifier.create())
224-
.ratePerSecond(1)
221+
.requestIdentifier(TQueryParamRequestIdentifier.create('my-key'))
225222
);
226223
```
224+
where `my-key` is query parameter key used to identify. So
225+
`http://myapp.fano?my-key=1` and `http://myapp.fano?my-key=2` will be identified as separate request.
227226

228-
If you need to use different ways to identify request, for example using unique key passed as query string or POST parameter, you can create a class which implements `IRequestIdentifier` interface and implement its `getId()` method. For example
227+
If you need to use different ways to identify request, for example using several unique key passed as query string or POST parameter, you can create a class which implements `IRequestIdentifier` interface and implement its `getId()` method. For example
229228

230229
```
231230
unit MyRequestIdentifierImpl;
@@ -255,6 +254,9 @@ type
255254
256255
implementation
257256
257+
uses
258+
md5;
259+
258260
(*!------------------------------------------------
259261
* get identifier from request
260262
*-----------------------------------------------
@@ -264,8 +266,11 @@ implementation
264266
function TMyRequestIdentifier.getId(
265267
const request : IRequest
266268
) : shortstring;
269+
var key, country : string;
267270
begin
268-
result := request.getParam('accesskey');
271+
key := request.getParam('accesskey');
272+
country := request.getParam('country');
273+
result := MD5Print(MD5String(country+key));
269274
end;
270275
```
271276
You can also create class inherit from `TAbstractRequestIdentifier` and implement its abstract method `getId()`.

0 commit comments

Comments
 (0)