link headers

This commit is contained in:
Kenneth Reitz
2012-08-21 00:43:05 +10:00
parent 2e71497e10
commit a032e7c392
+22 -2
View File
@@ -517,10 +517,30 @@ headers.::
>>> r = requests.head(url=url, auth=auth)
>>> print r.headers
// ...snip... //
...
'x-ratelimit-remaining': '4995'
'x-ratelimit-limit': '5000'
// ...snip... //
...
Excellent. Time to write a Python program that abuses the GitHub API in all
kinds of exciting ways, 4995 more times.
Link Headers
------------
Many HTTP APIs feature Link headers. They make APIs more self describing and discoverable.
GitHub uses these for `pagination <http://developer.github.com/v3/#pagination>`_ in their API, for example::
>>> url = 'https://api.github.com/users/kennethreitz/repos?page=1&per_page=10'
>>> r = requests.head(url=url)
>>> print r.headers['link']
...
'x-ratelimit-remaining': '4995'
'x-ratelimit-limit': '5000'
...
Requests will automatically parse these link headers and make them easily consumable: