Try 30 days of free premium.

How can i avoid retching the rate limit?

4456465 wrote a year ago: 1

I need to get information on 60+ shows in one go. My current solution to this is to make 1 call to the API for every show, which makes it 60+ calls.
This exceeds the limit on 20 calls every 10 seconds.

The reason i need to do this is that i need all the information on these 60+ shows to show this information in a table in my frontend.

Any good solutions on how to solve this?
 

Can i get information on several shows in 1 call?

Can i download the whole dataset and put it in my own db? (outdated info is an issue i can live with if this is the by far easiest solution ) ( If so, how do i get all the data)

Any other clever solution for my problem?  


david wrote a year ago: 2

There's two options. First, you could indeed download the whole dataset of shows and store it locally using the show index endpoint: https://www.tvmaze.com/api#show-index

Alternatively, consider the following:

We say at least, because rate limiting takes place on the backend but not on the edge cache. So if your client is only requesting common/popular endpoints like shows or episodes(as opposed to more unique endpoints like searches or embedding), you're likely to never hit the limit. For an optimal throughput, simply let your client back off for a few seconds when it receives a 429.

So if you're only accessing common endpoints like /shows/1, /shows/2, /shows/3 etc, you could implement an HTTP client that automatically pauses for a few seconds when it receives a HTTP 429 status code from our API, then automatically retries that request before moving on to the next one in the queue.

4456465 wrote a year ago: 1

@david wrote:
There's two options. First, you could indeed download the whole dataset of shows and store it locally using the show index endpoint: https://www.tvmaze.com/api#show-index

Alternatively, consider the following:

So if you're only accessing common endpoints like /shows/1, /shows/2, /shows/3 etc, you could implement an HTTP client that automatically pauses for a few seconds when it receives a HTTP 429 status code from our API, then automatically retries that request before moving on to the next one in the queue.

ok, nice

So this means that requesting https://api.tvmaze.com/search/shows?q=girls 60+ times will most likely give me 429-status

but requesting https://api.tvmaze.com/shows/139 etc. 60+ time will be ok?


david wrote a year ago: 2

@4456465 wrote:
ok, nice

So this means that requesting https://api.tvmaze.com/search/shows?q=girls 60+ times will most likely give me 429-status

but requesting https://api.tvmaze.com/shows/139 etc. 60+ time will be ok?

You'll most likely be OK. There's still a chance that you're unlucky enough to request 60 shows that don't exist in the edge cache. If you go for this route, I would encourage you to properly handle HTTP 429's either way to prevent random errors at some point in the future.

4456465 wrote a year ago: 1

@david wrote:
You'll most likely be OK. There's still a chance that you're unlucky enough to request 60 shows that don't exist in the edge cache. If you go for this route, I would encourage you to properly handle HTTP 429's either way so prevent random errors at some point in the future.

Ok. Thanks. ill probably do it in the https://api.tvmaze.com/shows/139 way then
 

Any good recommendations on how to handle this in JavaScript Vue3?

An if statement that checks 429 and shows the user "Sorry, try again in half a minute"?
 

And maybe having my TVMaze username in the HTTP header since it says: 

"While not required, we strongly recommend setting your client's HTTP User Agent to something that'll uniquely describe it. This allows us to identify your application in case of problems, or to proactively reach out to you.""


david wrote a year ago: 1

@4456465 wrote:
Any good recommendations on how to handle this in JavaScript Vue3?

An if statement that checks 429 and shows the user "Sorry, try again in half a minute"?

No, what I meant is that your code would automatically retry the request after a few seconds when we return a 429. You could look at something like https://www.npmjs.com/package/fetch-retry to accomplish that.

4456465 wrote a year ago: 1

@david wrote:
No, what I meant is that your code would automatically retry the request after a few seconds when we return a 429. You could look at something like https://www.npmjs.com/package/fetch-retry to accomplish that.

Ah, ok. Any particully timelimit? Im afraid of beeing banned:)


david wrote a year ago: 2

@4456465 wrote:
Ah, ok. Any particully timelimit? Im afraid of beeing banned:)

I'd suggest an exponential backoff. For example, something like retry #1 after one second, retry #2 ater two seconds, retry #3 after four seconds, etc.

Try 30 days of free premium.