Skip to content

Commit aec25f4

Browse files
add docs
1 parent f698ed8 commit aec25f4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/en/latest/plugins/limit-count.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,65 @@ Server: APISIX web server
344344
{"error_msg":"Requests are too frequent, please try again later."}
345345
```
346346

347+
### Customize Rate Limiting Headers
348+
349+
The following example demonstrates how you can use plugin metadata to customize the rate limiting response header names, which are by default `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and `X-RateLimit-Reset`.
350+
351+
Configure the plugin metadata for this plugin and update the headers:
352+
353+
```shell
354+
curl "http://127.0.0.1:9180/apisix/admin/plugin_metadata/limit-count" -X PUT -d '
355+
{
356+
"log_format": {
357+
"limit_header": "X-Custom-RateLimit-Limit",
358+
"remaining_header": "X-Custom-RateLimit-Remaining",
359+
"reset_header": "X-Custom-RateLimit-Reset"
360+
}
361+
}'
362+
```
363+
364+
Create a route with `limit-count` plugin that allows for a quota of 1 within a 30-second window per remote address:
365+
366+
```shell
367+
curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
368+
-H "X-API-KEY: ${ADMIN_API_KEY}" \
369+
-d '{
370+
"id": "limit-count-route",
371+
"uri": "/get",
372+
"plugins": {
373+
"limit-count": {
374+
"count": 1,
375+
"time_window": 30,
376+
"rejected_code": 429,
377+
"key_type": "var",
378+
"key": "remote_addr",
379+
"window_type": "sliding"
380+
}
381+
# highlight-end
382+
},
383+
"upstream": {
384+
"type": "roundrobin",
385+
"nodes": {
386+
"httpbin.org:80": 1
387+
}
388+
}
389+
}'
390+
```
391+
392+
Send a request to verify:
393+
394+
```shell
395+
curl -i "http://127.0.0.1:9080/get"
396+
```
397+
398+
You should receive an `HTTP/1.1 200 OK` response and see the following headers:
399+
400+
```text
401+
X-Custom-RateLimit-Limit: 1
402+
X-Custom-RateLimit-Remaining: 0
403+
X-Custom-RateLimit-Reset: 28
404+
```
405+
347406
## Delete Plugin
348407

349408
To remove the `limit-count` Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

0 commit comments

Comments
 (0)