summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAlex Chan <a.chan@wellcome.ac.uk>2017-10-24 07:27:55 +0100
committerAlex Chan <a.chan@wellcome.ac.uk>2017-10-24 07:27:55 +0100
commitc5ed41e00a2010fc251ed5655d9f1923c345878a (patch)
tree6ed61bf9c0b9667b58be11c18b7446a10df0896a /docs
parent40c5a8b0c28e2756e83ecfab0160ca3be37391e1 (diff)
downloadpython-requests-c5ed41e00a2010fc251ed5655d9f1923c345878a.tar.gz
Add an example of two hooks
Diffstat (limited to 'docs')
-rw-r--r--docs/user/advanced.rst12
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/user/advanced.rst b/docs/user/advanced.rst
index c24f6e5b..587b3fdc 100644
--- a/docs/user/advanced.rst
+++ b/docs/user/advanced.rst
@@ -452,12 +452,24 @@ If the callback function returns a value, it is assumed that it is to
replace the data that was passed in. If the function doesn't return
anything, nothing else is effected.
+::
+
+ def record_hook(r, *args, **kwargs):
+ r.hook_called = True
+ return r
+
Let's print some request method arguments at runtime::
>>> requests.get('http://httpbin.org', hooks={'response': print_url})
http://httpbin.org
<Response [200]>
+You can add multiple hooks to a single request. Let's call two hooks at once::
+
+ >>> r = requests.get('http://httpbin.org', hooks={'response': [print_url, record_hook]})
+ >>> r.hook_called
+ True
+
You can also add hooks to a ``Session`` instance. Any hooks you add will then
be called on every request made to the session. For example::