diff --git a/arango/database.py b/arango/database.py index e33bd5ae..a1fe8dc3 100644 --- a/arango/database.py +++ b/arango/database.py @@ -526,14 +526,23 @@ def response_handler(resp: Response) -> datetime: return self._execute(request, response_handler) - def echo(self) -> Result[Json]: - """Return details of the last request (e.g. headers, payload). - + def echo(self, body: Optional[Any] = None) -> Result[Json]: + """Return details of the last request (e.g. headers, payload), + or echo the given request body. + + :param body: The body of the request. Can be of any type + and is simply forwarded. If not set, the details of the last + request are returned. + :type body: dict | list | str | int | float | None :return: Details of the last request. :rtype: dict :raise arango.exceptions.ServerEchoError: If retrieval fails. """ - request = Request(method="get", endpoint="/_admin/echo") + request = ( + Request(method="get", endpoint="/_admin/echo") + if body is None + else Request(method="post", endpoint="/_admin/echo", data=body) + ) def response_handler(resp: Response) -> Json: if not resp.is_success: diff --git a/docs/admin.rst b/docs/admin.rst index 744b44b3..dc3dc030 100644 --- a/docs/admin.rst +++ b/docs/admin.rst @@ -54,6 +54,9 @@ database. # Echo the last request. sys_db.echo() + # Echo a request + sys_db.echo('request goes here') + # Reload the routing collection. sys_db.reload_routing() diff --git a/tests/test_database.py b/tests/test_database.py index da6307a4..29e0e336 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -166,6 +166,12 @@ def test_database_misc_methods(sys_db, db, bad_db, cluster): bad_db.echo() assert err.value.error_code in {11, 1228} + # Test echo (forward request) + body = "request goes here" + echo = db.echo(body) + assert isinstance(echo, dict) + assert echo["requestBody"] == body + # Test read_log with default parameters # Deprecated in 3.8.0 # TODO: Remove in future release