Skip to content

Commit bbc85e1

Browse files
committed
[ADD] developer: add js http service
closes #1293 Signed-off-by: Simon Genin (ges@odoo) <[email protected]>
1 parent 624131f commit bbc85e1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

content/developer/reference/frontend/services.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Reference List
120120
- read or modify cookies
121121
* - :ref:`effect <frontend/services/effect>`
122122
- display graphical effects
123+
* - :ref:`http <frontend/services/http>`
124+
- perform low level http calls
123125
* - :ref:`notification <frontend/services/notification>`
124126
- display notifications
125127
* - :ref:`router <frontend/services/router>`
@@ -343,6 +345,52 @@ Here, it is called in webclient.js to make it visible everywhere for the example
343345
:width: 600
344346
:align: center
345347

348+
.. _frontend/services/http:
349+
350+
Http Service
351+
------------
352+
353+
Overview
354+
~~~~~~~~
355+
356+
* Technical name: `http`
357+
* Dependencies: None
358+
359+
While most interactions between the client and the server in odoo are `RPCs` (`XMLHTTPRequest`), lower level
360+
control on requests may sometimes be required.
361+
362+
This service provides a way to send `get` and `post` `http requests <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods>`_.
363+
364+
API
365+
~~~
366+
367+
.. js:function:: async get(route[,readMethod = "json"])
368+
369+
:param string route: the url to send the request to
370+
:param string readMethod: the response content type. Can be "text", "json", "formData", "blob", "arrayBuffer".
371+
:returns: the result of the request with the format defined by the readMethod argument.
372+
373+
Sends a get request.
374+
375+
.. js:function:: async post(route [,params = {}, readMethod = "json"])
376+
377+
:param string route: the url to send the request to
378+
:param object params: key value data to be set in the form data part of the request
379+
:param string readMethod: the response content type. Can be "text", "json", "formData", "blob", "arrayBuffer".
380+
:returns: the result of the request with the format defined by the readMethod argument.
381+
382+
Sends a post request.
383+
384+
Example
385+
~~~~~~~
386+
387+
.. code-block:: javascript
388+
389+
const httpService = useService("http");
390+
const data = await httpService.get("https://something.com/posts/1");
391+
// ...
392+
await httpService.post("https://something.com/posts/1", { title: "new title", content: "new content" });
393+
346394
.. _frontend/services/notification:
347395

348396
Notification service

0 commit comments

Comments
 (0)