Help With "Throttling" HTTP Requests

I would like to know specifically how I should approach protecting the following code from POST request spam. I would like to know how to do this in such a way that a queue is built up when POSTS are submitted too quickly, and as such the queue carries out each outstanding POST in an orderly fashion:

local function Post(WebhookType, Data)
	HttpService:PostAsync(Webhooks[WebhookType], HttpService:JSONEncode(Data));
end

local LastPost = 0;
function Module:Post(WebhookType, Data)
	Post(WebhookType, Data);
end

As you can see, I can post here as quickly as I would like, but posting too fast would end up giving me a 429 (Posting too fast). Of course the client does not have any access to this module, this use case would be for perhaps logging chats where requests would be sent rather fast. I would just like to make sure I’m not essentially DoSing Discord or clogging up my own request queue while using this. If anybody has any solutions or questions, I’m very happy to respond.

bricknemesis

1 Like

I actually just saw a module that aims to do just that. Why not take a look?

1 Like