How to parse the rate.limit headers

I am trying to parse the rate limit headers, i.e I have some request to some helix endpoint and access the headers on data.headers after I issued a request with my token, however I can’t grab the data from the header, which I need.
My response looks like this
{ headers:
{ ‘Client-ID’: ‘myclientid’,
Accept: ‘application/vnd.twitchtv.v5+json’,
Authorization: ‘Bearer myAccessToken’ } }
{ connection: ‘close’,
‘content-length’: ‘2273’,
‘access-control-allow-origin’: ‘*’,
‘cache-control’: ‘no-cache, no-store, must-revalidate, private’,
‘content-type’: ‘application/json; charset=utf-8’,
expires: ‘0’,
pragma: ‘no-cache’,
‘ratelimit-limit’: ‘800’,
‘ratelimit-remaining’: ‘799’,
‘ratelimit-reset’: ‘1590589847’,
server: ‘envoy’,
‘timing-allow-origin’: ‘’,
‘twitch-trace-id’: ‘ae30829b90816a8a489677d99d760bf3’,
‘x-ctxlog-logid’: ‘1-5ece7996-3522785349169528b35ba92c’,
date: ‘Wed, 27 May 2020 14:30:46 GMT’,
‘x-served-by’: ‘cache-sea4464-SEA, cache-cph20620-CPH’,
‘x-cache’: ‘MISS, MISS’,
‘x-cache-hits’: ‘0, 0’,
‘x-timer’: ‘S1590589846.968417,VS0,VS0,VE212’,
vary: ‘Accept-Encoding’,
‘strict-transport-security’: ‘max-age=300’ }

How do I parse this object and get the strings:
‘ratelimit-limit’: ‘800’,
‘ratelimit-remaining’: ‘799’,
‘ratelimit-reset’: ‘1590589847’

Don’t need this with helix.

What language are you working in and/or what code do you already have?

Apologize for not specifying, I am using javascript and node.js basically I make a request with axios
i.e const object = await axios.get(´’, configObject);
and then I derive the headers from that request:
const rate_limit = object.headers;
and this is where I am stuck, I want to propegate the headers from that request into an object that I can use for all my requests.
Something like const APILimits = { //limits object defined here }
and then use that object in all my requests so I can keep track of rate limits
I hope this makes sense I will revert if clarification is needed

I have solved the issue, if anyone else is looking for this, just grab the header u want from the object with [‘ratelimit-remaining’]

yeah with javascript/axios is returns as a object, so just iterate as a object. Since the key name includes a - you can’t do thing.that-thing but thing['that-thing'] instead

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.