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.
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With