首页  >  文章  >  后端开发  >  API限速服务器

API限速服务器

Patricia Arquette
Patricia Arquette原创
2024-11-06 05:54:02241浏览

API Rate Limiting Server

该项目实现了一个具有速率限制的 HTTP 服务器。它确保每秒处理的请求数不超过 5 个。

目录

  • 简介
  • 特点
  • Github 链接
  • 安装
  • 端点
  • 用法
  • 测试
  • 许可证

介绍

API速率限制服务器限制每秒的请求数量,以防止滥用并有效管理服务器负载。它提供详细的日志记录和健康检查端点来监控服务器状态。

特征

  • 速率限制为每秒 5 个请求
  • 用于监控服务器状态的健康检查端点
  • 详细的请求记录

GitHub 链接

https://github.com/surajupadhaya/Simple-API-RateLimit

安装

1. Clone the repository:

   #git clone https://github.com/surajupadhaya/Simple-API-RateLimit
   #cd Simple-API-RateLimit


2. Install dependencies:
   #go mod tidy

端点

1. /: Default route returns a "stupid request" message with status 400.

2. /healthcheck: Endpoint to check the health status of the server. Returns "Health Passed" if the /healthcheck file exists, otherwise "Health Failed".

3. /api/v1/product: Example endpoint for the product API. Returns "This is a Product API" if the /api/v1/product file exists, otherwise "There is no Product API".

用法

1. Run the API rate limiting server:
   #go run main.go
2. Access the server:
   #curl -w %{http_code}http://localhost:8080 

测试

1. Run Httperf tool to test the rate limiting 
Below httperf command is sending 6 connection parallelly in one sec 
Out of 6 only 1 will receive 503 code (due to throttling) remaining will receive based on behavior 
#httperf --server localhost --port 8080 --uri /healthcheck --num-conns 6

Sample output :

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/842aqi7lmzqw7sa1mcs1.png)



执照

This project is licensed under the MIT License. See the LICENSE file for details.

This `README.md` should cover the current state of your project, focusing on the API rate limiting aspect. Ready to roll? ?


This should cover everything your project entails. You can add, modify, or remove sections as needed. ?

以上是API限速服务器的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn