Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Rate Limits' Documentation #1742

Merged
merged 6 commits into from
Jan 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ var user = await client.User.Current();
```

### Too Much of a Good Thing: Dealing with API Rate Limits
Like any popular API, Github needs to throttle some requests. The OctoKit.NET client allows you to get some insight into how many requests you have left and when you can start making requests again. It does this via the `ApiInfo` object and the `GetLastApiInfo()` method.
Like any popular API, Github needs to throttle some requests. The OctoKit.NET client allows you to get some insight into how many requests you have left and when you can start making requests again.

In fact, there are two ways to get the Rate Limits via OctoKit.NET. Calling `GitHubClient.GetLastApiInfo()` returns the Rate Limit status which has been returned with the last api call. So, calling `GitHubClient.GetLastApiInfo()` will not send any extra HTTP requests to GitHub's servers.

Example usage:

```csharp
GithubClient client;
GitHubClient client;
//Create & initialize the client here

// Prior to first API call, this will be null, because it only deals with the last call.
Expand All @@ -90,6 +92,31 @@ var howManyRequestsDoIHaveLeft = rateLimit?.Remaining;
var whenDoesTheLimitReset = rateLimit?.Reset;
```

However, if in some cases you need to get the Rate Limit directly from Github, you should call `GitHubClient.Miscellaneous.GetRateLimits()`.

Example usage:

```csharp
GitHubClient client;
//Create & initialize the client here

var miscellaneousRateLimit = await client.Miscellaneous.GetRateLimits();

// The "core" object provides your rate limit status except for the Search API.
var coreRateLimit = miscellaneousRateLimit.Resources.Core;

var howManyCoreRequestsCanIMakePerHour = coreRateLimit.Limit;
var howManyCoreRequestsDoIHaveLeft = coreRateLimit.Remaining;
var whenDoesTheCoreLimitReset = coreRateLimit.Reset;

// the "search" object provides your rate limit status for the Search API.
var searchRateLimit = miscellaneousRateLimit.Resources.Search;

var howManySearchRequestsCanIMakePerMinute = searchRateLimit.Limit;
var howManySearchRequestsDoIHaveLeft = searchRateLimit.Remaining;
var whenDoesTheSearchLimitReset = searchRateLimit.Reset;
```

An authenticated client will have a significantly higher limit than an anonymous client.

For more information on the API and understanding rate limits, you may want to consult [the Github API docs on rate limits](https://developer.github.com/v3/#rate-limiting).