Add an example of two hooks

This commit is contained in:
Alex Chan
2017-10-24 07:27:55 +01:00
parent 40c5a8b0c2
commit c5ed41e00a
+12
View File
@@ -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::