diff --git a/content/developer/reference/frontend/services.rst b/content/developer/reference/frontend/services.rst index fb6add488..b537d3660 100644 --- a/content/developer/reference/frontend/services.rst +++ b/content/developer/reference/frontend/services.rst @@ -120,6 +120,8 @@ Reference List - read or modify cookies * - :ref:`effect ` - display graphical effects + * - :ref:`http ` + - perform low level http calls * - :ref:`notification ` - display notifications * - :ref:`router ` @@ -343,6 +345,52 @@ Here, it is called in webclient.js to make it visible everywhere for the example :width: 600 :align: center +.. _frontend/services/http: + +Http Service +------------ + +Overview +~~~~~~~~ + +* Technical name: `http` +* Dependencies: None + +While most interactions between the client and the server in odoo are `RPCs` (`XMLHTTPRequest`), lower level +control on requests may sometimes be required. + +This service provides a way to send `get` and `post` `http requests `_. + +API +~~~ + +.. js:function:: async get(route[,readMethod = "json"]) + + :param string route: the url to send the request to + :param string readMethod: the response content type. Can be "text", "json", "formData", "blob", "arrayBuffer". + :returns: the result of the request with the format defined by the readMethod argument. + + Sends a get request. + +.. js:function:: async post(route [,params = {}, readMethod = "json"]) + + :param string route: the url to send the request to + :param object params: key value data to be set in the form data part of the request + :param string readMethod: the response content type. Can be "text", "json", "formData", "blob", "arrayBuffer". + :returns: the result of the request with the format defined by the readMethod argument. + + Sends a post request. + +Example +~~~~~~~ + +.. code-block:: javascript + + const httpService = useService("http"); + const data = await httpService.get("https://something.com/posts/1"); + // ... + await httpService.post("https://something.com/posts/1", { title: "new title", content: "new content" }); + .. _frontend/services/notification: Notification service