Skip to content

Commit ef0b26b

Browse files
feat: Add link to bored-engineer/github-conditional-http-transport to conditional requests documentation (#3469)
1 parent 0ccbfaf commit ef0b26b

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,28 @@ if _, ok := err.(*github.AcceptedError); ok {
257257

258258
### Conditional Requests ###
259259

260-
The GitHub API has good support for conditional requests which will help
261-
prevent you from burning through your rate limit, as well as help speed up your
262-
application. `go-github` does not handle conditional requests directly, but is
263-
instead designed to work with a caching `http.Transport`. We recommend using
264-
[gregjones/httpcache](https://github.com/gregjones/httpcache) for that. For example:
260+
The GitHub REST API has good support for [conditional HTTP requests](https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#use-conditional-requests-if-appropriate)
261+
via the `ETag` header which will help prevent you from burning through your
262+
rate limit, as well as help speed up your application. `go-github` does not
263+
handle conditional requests directly, but is instead designed to work with a
264+
caching `http.Transport`.
265+
266+
Typically, an [RFC 7234](https://datatracker.ietf.org/doc/html/rfc7234)
267+
compliant HTTP cache such as [gregjones/httpcache](https://github.com/gregjones/httpcache)
268+
is recommended, ex:
265269

266270
```go
267271
import "github.com/gregjones/httpcache"
268272

269-
client := github.NewClient(
270-
httpcache.NewMemoryCacheTransport().Client()
271-
).WithAuthToken(os.Getenv("GITHUB_TOKEN"))
273+
client := github.NewClient(
274+
httpcache.NewMemoryCacheTransport().Client()
275+
).WithAuthToken(os.Getenv("GITHUB_TOKEN"))
272276
```
273277

274-
Learn more about GitHub conditional requests in
275-
["Use conditional requests if appropriate"](https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api?apiVersion=2022-11-28#use-conditional-requests-if-appropriate).
278+
Alternatively, the [bored-engineer/github-conditional-http-transport](https://github.com/bored-engineer/github-conditional-http-transport)
279+
package relies on (undocumented) GitHub specific cache logic and is
280+
recommended when making requests using short-lived credentials such as a
281+
[GitHub App installation token](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation).
276282

277283
### Creating and Updating Resources ###
278284

github/doc.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,17 @@ To detect this condition of error, you can check if its type is
138138
139139
# Conditional Requests
140140
141-
The GitHub API has good support for conditional requests which will help
142-
prevent you from burning through your rate limit, as well as help speed up your
143-
application. go-github does not handle conditional requests directly, but is
144-
instead designed to work with a caching http.Transport. We recommend using
145-
https://github.com/gregjones/httpcache for that.
141+
The GitHub REST API has good support for conditional HTTP requests
142+
via the ETag header which will help prevent you from burning through your
143+
rate limit, as well as help speed up your application. go-github does not
144+
handle conditional requests directly, but is instead designed to work with a
145+
caching http.Transport.
146+
147+
Typically, an RFC 7234 compliant HTTP cache such as https://github.com/gregjones/httpcache
148+
is recommended. Alternatively, the https://github.com/bored-engineer/github-conditional-http-transport
149+
package relies on (undocumented) GitHub specific cache logic and is
150+
recommended when making requests using short-lived credentials such as a
151+
GitHub App installation token.
146152
147153
Learn more about GitHub conditional requests at
148154
https://docs.github.com/rest/overview/resources-in-the-rest-api#conditional-requests.

0 commit comments

Comments
 (0)