DEV Community

suraj upadhaya
suraj upadhaya

Posted on

API Rate Limiting Server

This project implements an HTTP server with rate limiting. It ensures no more than 5 requests per second can be processed.

Table of Contents

Introduction

The API rate limiting server limits the number of requests per second to prevent abuse and manage server load effectively. It provides detailed logging and health check endpoints to monitor server status.

Features

  • Rate limiting to 5 requests per second
  • Health check endpoint to monitor server status
  • Detailed request logging

Github Link

https://github.com/surajupadhaya/Simple-API-RateLimit
Enter fullscreen mode Exit fullscreen mode

Installation

1. Clone the repository:

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


2. Install dependencies:
   #go mod tidy

Enter fullscreen mode Exit fullscreen mode

Endpoints

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".
Enter fullscreen mode Exit fullscreen mode

Usage

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

Test

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)



Enter fullscreen mode Exit fullscreen mode

License

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. 🚀
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
ravavyr profile image
Ravavyr

How is this a "project"
It's a single security feature that you should be configuring onto a real project.