Requests API
1

Table of Contents

  • requests
  • The User Guide
    • 1. Introduction
    • 2. Quickstart
    • 3. Advanced Usage
      • 3.1. Session Objects
      • 3.2. Request and Response Objects
      • 3.3. Prepared Requests
      • 3.4. SSL Cert Verification
      • 3.5. CA Certificates
      • 3.6. Body Content Workflow
      • 3.7. Keep-Alive
      • 3.8. Streaming Uploads
      • 3.9. Chunk-Encoded Requests
      • 3.10. POST Multiple Multipart-Encoded Files
      • 3.11. Event Hooks
      • 3.12. Custom Authentication
      • 3.13. Streaming Requests
      • 3.14. Proxies
      • 3.15. Compliance
      • 3.16. HTTP Verbs
      • 3.17. Link Headers
      • 3.18. Transport Adapters
      • 3.19. Blocking Or Non-Blocking?
      • 3.20. Header Ordering
      • 3.21. Timeouts
    • 4. Authentication
  • Other Stuffs from official doc
Requests API
  • Docs »
  • The User Guide »
  • 3. Advanced Usage »
  • 3.17. Link Headers
  • View page source

3.17. 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)
>>> r.headers['link']
'<https://api.github.com/users/kennethreitz/repos?page=2&per_page=10>; rel="next", <https://api.github.com/users/kennethreitz/repos?page=6&per_page=10>; rel="last"'

Requests will automatically parse these link headers and make them easily consumable:

>>> r.links["next"]
{'url': 'https://api.github.com/users/kennethreitz/repos?page=2&per_page=10', 'rel': 'next'}

>>> r.links["last"]
{'url': 'https://api.github.com/users/kennethreitz/repos?page=7&per_page=10', 'rel': 'last'}
Next Previous

© Copyright .

Built with Sphinx using a theme provided by Read the Docs.