Skip to content

Commit b75b61a

Browse files
barmintordmolesUC
andcommitted
document an approach to configuring a faraday client to retry
Co-authored-by: David Moles <[email protected]>
1 parent 46903f2 commit b75b61a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ For example to initiate a ListRecords request to pubmed you can:
4646
end
4747
```
4848

49+
### Retry-After
50+
This library depends on faraday, but allows a wide range of versions. Depending on the client application's installed version of faraday, there may be different middleware libraries required to support automatically retrying requests that are rate limited/denied with a `Retry-After` header. The OAI client can, however, accept an externally configured faraday http client for handling this. For example, to retry on `429 Too Many Requests`:
51+
52+
```ruby
53+
require 'oai'
54+
require 'faraday_middleware' # if using faraday version < 2
55+
http_client = Faraday.new do |conn|
56+
conn.request(:retry, max: 5, retry_statuses: 429)
57+
conn.response(:follow_redirects, limit: 5)
58+
conn.adapter :net_http
59+
end
60+
client = OAI::Client.new(base_url, http: http_client)
61+
opts = {from:'2012-03-01', until:'2012-04-01', metadata_prefix:'oai_dc'}
62+
puts client.list_records(opts).full.count
63+
```
64+
4965
See {OAI::Client} for more details
5066

5167
Server

0 commit comments

Comments
 (0)