.. rubric:: :doc:`index` jsonrpcclient over HTTP *********************** Send JSON-RPC requests over HTTP. Installation ============ .. code-block:: sh $ pip install jsonrpcclient requests Usage ===== Set the server details:: >>> from jsonrpcclient.http_server import HTTPServer >>> server = HTTPServer('http://pets.com/api') .. include:: _includes/requests.rst Configuration ============= The Requests module's `Session `_ is available so you can configure that before sending any requests. For example, for SSL authentication:: >>> server.session.verify = '/path/to/cert' Basic Auth:: >>> server.session.auth = ('user', 'pass') Custom HTTP headers:: >>> server.session.headers.update({'Content-Type': 'application/json-rpc'}) You can also configure the `Request `_ options when calling ``send``:: >>> server.send(req, auth=('user', 'pass')) >>> server.send(req, headers={'Content-Type': 'application/json-rpc'}) As in the requests library, any dictionaries passed to ``send`` in named arguments will be merged with the session-level values that are set. The method-level parameters override session parameters. Exceptions ========== The Requests module raises a `requests.exceptions.RequestException `_ if there's a problem transferring the message. Other exceptions raised are: .. include:: _includes/exceptions.rst Logging ======= .. include:: _includes/logging.rst The request format has these fields: :endpoint: The server endpoint, eg. ``http://example.com/api``. :http_headers: The full HTTP headers. :message: The JSON request (the body). The response format has these fields: :endpoint: The server endpoint, eg. ``http://example.com/api``. :http_code: The HTTP status code received from the server, eg. ``400``. :http_reason: The description of the status code, eg. ``BAD REQUEST``. :http_headers: The full HTTP headers. :message: The JSON response (the body). Examples ======== - `HTTP Client using Requests `_ :doc:`Back home `