Skip to content

Conversation

@deepak30012004
Copy link

title: Add express-rate-limit to POST /api/products route

summary: |
This PR adds rate limiting to the POST /api/products endpoint using the
express-rate-limit package to prevent abuse and ensure API stability.

what_i_did:

  • Installed express-rate-limit via npm install express-rate-limit.
  • Configured a rate limiter to allow 5 requests per minute per IP.
  • Applied the rate limiter only to the POST /api/products route in index.js.

why: |
To:

  • Prevent spam or abuse of the product submission route.
  • Improve backend security.
  • Demonstrate use of security middleware as part of good API practices.

how_to_test:

  • Run npm install.
  • Start the server with node index.js.
  • Use Postman or curl to send more than 5 POST requests to /api/products within 1 minute.
  • After the 5th request, you should receive a 429 response with the custom error message.

future_suggestions:

  • Switch to Redis-based rate limiter for distributed systems or production environments.
  • Apply rate limiting globally or to other sensitive endpoints as needed.
  • Allow authenticated users to have a higher request quota.
  • 👉 If you want to make more requests per minute:
    • Increase the max value in the rate limiter configuration.
    • Contact the admin or implement a premium tier with higher limits.
    • Use API keys or user roles to set dynamic rate limits.

note: Let me know if you'd like me to help implement any of these in the next PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants