1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
API Reference
=============
This page lists all of the interfaces exposed by the `treq` package.
Making Requests
---------------
The :py:mod:`treq` module provides several convenience functions for making requests.
These functions all create a default :py:class:`treq.client.HTTPClient` instance and pass their arguments to the appropriate :py:class:`~treq.client.HTTPClient` method.
.. module:: treq
.. autofunction:: request
.. autofunction:: get
.. autofunction:: head
.. autofunction:: post
.. autofunction:: put
.. autofunction:: patch
.. autofunction:: delete
Accessing Content
-----------------
.. autofunction:: collect
.. autofunction:: content
.. autofunction:: text_content
.. autofunction:: json_content
The HTTP Client
===============
.. module:: treq.client
:class:`treq.client.HTTPClient` has methods that match the signatures of the convenience request functions in the :mod:`treq` module.
.. autoclass:: HTTPClient(agent, cookiejar=None, data_to_body_producer=IBodyProducer)
.. automethod:: request
.. automethod:: get
.. automethod:: head
.. automethod:: post
.. automethod:: put
.. automethod:: patch
.. automethod:: delete
Augmented Response Objects
--------------------------
:func:`treq.request`, :func:`treq.get`, etc. return an object which provides :class:`twisted.web.iweb.IResponse`, plus a few additional convenience methods:
.. module:: treq.response
.. class:: _Response
.. automethod:: collect
.. automethod:: content
.. automethod:: json
.. automethod:: text
.. automethod:: history
.. automethod:: cookies
Inherited from :class:`twisted.web.iweb.IResponse`:
:ivar version: See :attr:`IResponse.version <twisted.web.iweb.IResponse.version>`
:ivar code: See :attr:`IResponse.code <twisted.web.iweb.IResponse.code>`
:ivar phrase: See :attr:`IResponse.phrase <twisted.web.iweb.IResponse.phrase>`
:ivar headers: See :attr:`IResponse.headers <twisted.web.iweb.IResponse.headers>`
:ivar length: See :attr:`IResponse.length <twisted.web.iweb.IResponse.length>`
:ivar request: See :attr:`IResponse.request <twisted.web.iweb.IResponse.request>`
:ivar previousResponse: See :attr:`IResponse.previousResponse <twisted.web.iweb.IResponse.previousResponse>`
.. method:: deliverBody(protocol)
See :meth:`IResponse.deliverBody() <twisted.web.iweb.IResponse.deliverBody>`
.. method:: setPreviousResponse(response)
See :meth:`IResponse.setPreviousResponse() <twisted.web.iweb.IResponse.setPreviousResponse>`
Authentication
--------------
.. module:: treq.auth
.. autofunction:: add_auth
.. autofunction:: add_basic_auth
.. autoexception:: UnknownAuthConfig
Cookies
-------
.. module:: treq.cookies
.. autofunction:: scoped_cookie
.. autofunction:: search
Test Helpers
------------
.. module:: treq.testing
The :mod:`treq.testing` module contains tools for in-memory testing of HTTP clients and servers.
StubTreq Objects
~~~~~~~~~~~~~~~~
.. class:: treq.testing.StubTreq(resource)
:class:`StubTreq` implements the same interface as the :mod:`treq` module
or the :class:`~treq.client.HTTPClient` class, with the limitation that it
does not support the ``files`` argument.
.. method:: flush()
Flush all data between pending client/server pairs.
This is only necessary if a :obj:`Resource` under test returns
:obj:`NOT_DONE_YET` from its ``render`` method, making a response
asynchronous. In that case, after each write from the server,
:meth:`flush()` must be called so the client can see it.
As the methods on :class:`treq.client.HTTPClient`:
.. method:: request
See :func:`treq.request()`.
.. method:: get
See :func:`treq.get()`.
.. method:: head
See :func:`treq.head()`.
.. method:: post
See :func:`treq.post()`.
.. method:: put
See :func:`treq.put()`.
.. method:: patch
See :func:`treq.patch()`.
.. method:: delete
See :func:`treq.delete()`.
RequestTraversalAgent Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: treq.testing.RequestTraversalAgent
:members:
RequestSequence Objects
~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: treq.testing.RequestSequence
:members:
StringStubbingResource Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: treq.testing.StringStubbingResource
:members:
HasHeaders Objects
~~~~~~~~~~~~~~~~~~
.. autoclass:: treq.testing.HasHeaders
:members:
MultiPartProducer Objects
-------------------------
:class:`treq.multipart.MultiPartProducer` is used internally when making requests which involve files.
.. automodule:: treq.multipart
:members:
|