Metadata-Version: 2.1
Name: odoo-addon-webservice_core
Version: 18.0.1.0.1.1
Requires-Python: >=3.10
Requires-Dist: odoo==18.0.*
Requires-Dist: openupgradelib
Requires-Dist: requests
Summary: Webservice backend: auth & call features, no extra dependencies
Home-page: https://github.com/OCA/web-api
License: AGPL-3
Author: Creu Blanca, Camptocamp, Odoo Community Association (OCA)
Author-email: support@odoo-community.org
Classifier: Programming Language :: Python
Classifier: Framework :: Odoo
Classifier: Framework :: Odoo :: 18.0
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
Classifier: Development Status :: 5 - Production/Stable
Description-Content-Type: text/x-rst

.. image:: https://odoo-community.org/readme-banner-image
   :target: https://odoo-community.org/get-involved?utm_source=readme
   :alt: Odoo Community Association

===============
WebService Core
===============

.. 
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! This file is generated by oca-gen-addon-readme !!
   !! changes will be overwritten.                   !!
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   !! source digest: sha256:9dd7160ee7fd0096aca6fbcff8f116f82b9b8dc078bee3f766384da680537b16
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
    :target: https://odoo-community.org/page/development-status
    :alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
    :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
    :target: https://github.com/OCA/web-api/tree/18.0/webservice_core
    :alt: OCA/web-api
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
    :target: https://translation.odoo-community.org/projects/web-api-18-0/web-api-18-0-webservice_core
    :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
    :target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=18.0
    :alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module provides the ``webservice.backend`` model with its
authentication (public, username/password, API key) and HTTP call
features (``get``/``post``/``put``).

It has no dependency on ``component`` or ``server_environment``, so it
can be used as a lightweight building block by any module needing to
configure and call an outbound webservice, without pulling in extra
frameworks.

**Table of contents**

.. contents::
   :local:

Configuration
=============

Go to *Settings > Technical > WebService Backend* (requires the
*Administration / Settings* group) and create a new backend:

- **Name** / **Technical Name**: a label and a unique technical key
  you'll use to look the backend up from code (e.g. ``env.ref`` is not
  used here; search by ``tech_name`` instead).
- **Protocol**: only ``HTTP Request`` is available in this module.
- **URL**: the base URL every call is relative to, e.g.
  ``https://api.example.com``. It may contain ``{placeholder}`` tokens
  (see *Usage*), e.g. ``https://api.example.com/{endpoint}``.
- **Content-Type**: optional default ``Content-Type`` header for every
  call.

Then configure authentication via **Auth Type**:

- **Public**: no credentials needed.
- **Username & password**: sent as HTTP Basic Auth. Requires
  **Username** and **Password**.
- **API Key**: sent as a custom header. Requires **API Key** and **API
  Key header** (the header name to send it under, e.g. ``X-Api-Key``).

Required fields depend on the selected auth type; the form only shows
and requires the ones that apply, and saving enforces it.

Usage
=====

Look up the backend (e.g. by its technical name) and call it:

.. code:: python

   backend = env["webservice.backend"].search([("tech_name", "=", "my_api")])
   result = backend.call("get")  # -> requests.Response
   result.content
   result.status_code

``call(method, *args, **kwargs)`` accepts any of the standard HTTP verbs
(``get``, ``post``, ``put``, ``delete``) and forwards everything else to
`requests <https://requests.readthedocs.io/>`__, so any of its keyword
arguments work too (``data``, ``json``, ``params``, ``files``, ...):

.. code:: python

   backend.call("post", data=b"<xml>...</xml>")
   backend.call("post", json={"foo": "bar"})

**URL**: by default the backend's own ``url`` is used. Pass ``url`` to
hit a different path - relative paths are appended to the backend's URL,
a full ``http(s)://`` URL is used as-is:

.. code:: python

   backend.call("get", url="orders")  # -> <backend url>/orders
   backend.call("get", url="https://other.example.com/orders")

If the backend's URL (or the ``url`` passed above) contains
``{placeholder}`` tokens, fill them with ``url_params``:

.. code:: python

   # backend.url == "https://api.example.com/{endpoint}"
   backend.call("get", url_params={"endpoint": "orders"})

**Headers**: pass ``headers`` to add/override headers for that call;
they are merged on top of the backend's own ``Content-Type`` and
auth-derived headers (e.g. the API key header):

.. code:: python

   backend.call("get", headers={"X-Request-Id": "42"})

**Auth override**: pass ``auth`` to bypass the backend's configured auth
type for a single call (same format ``requests`` itself accepts, e.g. a
``(user, password)`` tuple):

.. code:: python

   backend.call("get", auth=("other_user", "other_password"))

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20webservice_core%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Creu Blanca
* Camptocamp

Contributors
------------

- Simone Orsi <simone.orsi@camptocamp.com>
- Enric Tobella <etobella@creublanca.es>
- Alexandre Fayolle <alexandre.fayolle@camptocamp.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
   :alt: Odoo Community Association
   :target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
    :target: https://github.com/simahawk
    :alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk| 

This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/18.0/webservice_core>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
