From a032e7c3925eb07a9d9df11920e4f1b2727ab4a0 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 21 Aug 2012 00:43:05 +1000 Subject: [PATCH] link headers --- docs/user/advanced.rst | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst index 0ac450d..d0e0425 100644 --- a/docs/user/advanced.rst +++ b/docs/user/advanced.rst @@ -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 `_ 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: + + + -- 2.34.1