Skip to content
Myr

link headers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 2e71497 · Browse files · 1 file+22 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+22 added−2 removed

  • other:+22 added−2 removed

1 file+22 added−2 removed

modified:docs/user/advanced.rst+22 added-2 removed
515 unmodified lines
516headers.::517518 >>> r = requests.head(url=url, auth=auth)519 >>> print r.headers520 // ...snip... //520 ...521 'x-ratelimit-remaining': '4995'522 'x-ratelimit-limit': '5000'523 // ...snip... //523 ...524525Excellent. Time to write a Python program that abuses the GitHub API in all526kinds of exciting ways, 4995 more times.527528Link Headers529------------530531Many HTTP APIs feature Link headers. They make APIs more self describing and discoverable.532533GitHub uses these for `pagination <http://developer.github.com/v3/#pagination>`_ in their API, for example::534535 >>> url = 'https://api.github.com/users/kennethreitz/repos?page=1&per_page=10'536 >>> r = requests.head(url=url)537 >>> print r.headers['link']538 ...539 'x-ratelimit-remaining': '4995'540 'x-ratelimit-limit': '5000'541 ...542543Requests will automatically parse these link headers and make them easily consumable:544545546