Skip to content

Custom Requests #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions arangoasync/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2861,6 +2861,21 @@ def response_handler(resp: Response) -> Any:

return await self._executor.execute(request, response_handler)

async def request(self, request: Request) -> Result[Response]:
"""Execute a custom request.

Args:
request (Request): Request object to be executed.

Returns:
Response: Response object containing the result of the request.
"""

def response_handler(resp: Response) -> Response:
return resp

return await self._executor.execute(request, response_handler)


class StandardDatabase(Database):
"""Standard database API wrapper.
Expand Down
7 changes: 7 additions & 0 deletions docs/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ information.

from arangoasync import ArangoClient
from arangoasync.auth import Auth
from arangoasync.request import Method, Request

# Initialize the client for ArangoDB.
async with ArangoClient(hosts="http://localhost:8529") as client:
Expand Down Expand Up @@ -60,4 +61,10 @@ information.
# Delete the database. Note that the new users will remain.
await sys_db.delete_database("test")

# Example of a custom request
request = Request(
method=Method.POST, endpoint="/_admin/execute", data="return 1".encode("utf-8")
)
response = await sys_db.request(request)

See :class:`arangoasync.client.ArangoClient` and :class:`arangoasync.database.StandardDatabase` for API specification.
9 changes: 9 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import datetime
import json

import pytest
from packaging import version
Expand Down Expand Up @@ -36,6 +37,7 @@
ServerTimeError,
ServerVersionError,
)
from arangoasync.request import Method, Request
from arangoasync.typings import CollectionType, KeyOptions, UserInfo
from tests.helpers import generate_col_name, generate_db_name, generate_username

Expand Down Expand Up @@ -157,6 +159,13 @@ async def test_database_misc_methods(
)
await db.compact()

# Custom Request
request = Request(
method=Method.POST, endpoint="/_admin/execute", data="return 1".encode("utf-8")
)
response = await sys_db.request(request)
assert json.loads(response.raw_body) == 1


@pytest.mark.asyncio
async def test_create_drop_database(
Expand Down
Loading