Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API limit exceeded: how to increase the rate limit in front-end apps

After some HTTP requests to the GitHub API, it starts refusing the calls saying:

API rate limit exceeded for xxx.xxx.xxx.xxx. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)

Now, there is a way to increase the unauthenticated rate limit for OAuth applications which involves using the client secret.

Of course we don't want to put or client secret on the public source code of a front-end app, as also the documentation recommends:

Note: Never share your client secret with anyone or include it in client-side browser code. Use the method shown here only for server-to-server calls.

so I was wondering what's the best way to solve the issue of the rate limit in a front end application.

like image 473
Francesco Borzi Avatar asked Oct 30 '22 07:10

Francesco Borzi


1 Answers

It is quite old question, however I managed to extend the limit from 60 to 5000. I am putting the client_secret to Header:Authorization - it is my private app, so I do not care about the security. Looking for the solution I have found that you can put mode='cors' to initRequest and you are able to send CORS request to GitHub API.

TypeScript class example: Typscript simple class exmaple e.g:

export default class AppRequestInit implements RequestInit {

  public method: string = 'GET';
  public headers: Headers = new Headers();
  public mode: RequestMode = 'cors';

  constructor() {
    this.headers.set('Content-Type', 'application/json');
    this.headers.append('Authorization', 'token XXXXXXXXXXXXXXXX');
  }
}

usage: fetch('https://api.github.com/users/USERNAME', new AppRequestInit())
like image 185
proti Avatar answered Jan 02 '23 21:01

proti