Develop serverless edge functions with PubNub Functions 2.0
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.79x
Baseline
Agent success rate without this tile
52%
You are building a PubNub Before Publish function that acts as a throttle for an API channel. Users on a "free" tier are allowed 100 requests per hour and "pro" tier users get 1000 per hour. The function should check the user's request count within the current time window and either allow or block the message. The function also needs to look up the user's tier from storage and attach remaining quota information to the message.
Be mindful that PubNub Functions have strict limits on the number of external operations that can be performed in a single execution.
Write a PubNub Before Publish function (throttle.js) that:
throttle.js file containing a complete PubNub Function implementing the request throttle.