-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added client-level REST helpers. (#544)
* Added client-level REST helpers. Signed-off-by: dblock <[email protected]> * Move functions into an .http namespace. Signed-off-by: dblock <[email protected]> * Poetry update in samples. Signed-off-by: dblock <[email protected]> * Fix: typo. Signed-off-by: dblock <[email protected]> * Clarified what to use in which older versions. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,102 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Http Client | ||
|
||
```{eval-rst} | ||
.. autoclass:: opensearchpy.client.http.HttpClient | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# -*- coding: utf-8 -*- | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
# | ||
# Modifications Copyright OpenSearch Contributors. See | ||
# GitHub history for details. | ||
|
||
from typing import Any, Mapping, Optional | ||
|
||
from .client import Client | ||
from .utils import NamespacedClient | ||
|
||
|
||
class HttpClient(NamespacedClient): | ||
def __init__(self, client: Client) -> None: | ||
super(HttpClient, self).__init__(client) | ||
|
||
async def get( | ||
self, | ||
url: str, | ||
headers: Optional[Mapping[str, Any]] = None, | ||
params: Optional[Mapping[str, Any]] = None, | ||
body: Any = None, | ||
) -> Any: | ||
""" | ||
Perform a GET request and return the data. | ||
:arg url: absolute url (without host) to target | ||
:arg headers: dictionary of headers, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class | ||
:arg params: dictionary of query parameters, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class for serialization | ||
:arg body: body of the request, will be serialized using serializer and | ||
passed to the connection | ||
""" | ||
return await self.transport.perform_request( | ||
"GET", url=url, headers=headers, params=params, body=body | ||
) | ||
|
||
async def head( | ||
self, | ||
url: str, | ||
headers: Optional[Mapping[str, Any]] = None, | ||
params: Optional[Mapping[str, Any]] = None, | ||
body: Any = None, | ||
) -> Any: | ||
""" | ||
Perform a HEAD request and return the data. | ||
:arg url: absolute url (without host) to target | ||
:arg headers: dictionary of headers, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class | ||
:arg params: dictionary of query parameters, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class for serialization | ||
:arg body: body of the request, will be serialized using serializer and | ||
passed to the connection | ||
""" | ||
return await self.transport.perform_request( | ||
"HEAD", url=url, headers=headers, params=params, body=body | ||
) | ||
|
||
async def post( | ||
self, | ||
url: str, | ||
headers: Optional[Mapping[str, Any]] = None, | ||
params: Optional[Mapping[str, Any]] = None, | ||
body: Any = None, | ||
) -> Any: | ||
""" | ||
Perform a POST request and return the data. | ||
:arg url: absolute url (without host) to target | ||
:arg headers: dictionary of headers, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class | ||
:arg params: dictionary of query parameters, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class for serialization | ||
:arg body: body of the request, will be serialized using serializer and | ||
passed to the connection | ||
""" | ||
return await self.transport.perform_request( | ||
"POST", url=url, headers=headers, params=params, body=body | ||
) | ||
|
||
async def delete( | ||
self, | ||
url: str, | ||
headers: Optional[Mapping[str, Any]] = None, | ||
params: Optional[Mapping[str, Any]] = None, | ||
body: Any = None, | ||
) -> Any: | ||
""" | ||
Perform a DELETE request and return the data. | ||
:arg url: absolute url (without host) to target | ||
:arg headers: dictionary of headers, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class | ||
:arg params: dictionary of query parameters, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class for serialization | ||
:arg body: body of the request, will be serialized using serializer and | ||
passed to the connection | ||
""" | ||
return await self.transport.perform_request( | ||
"DELETE", url=url, headers=headers, params=params, body=body | ||
) | ||
|
||
async def put( | ||
self, | ||
url: str, | ||
headers: Optional[Mapping[str, Any]] = None, | ||
params: Optional[Mapping[str, Any]] = None, | ||
body: Any = None, | ||
) -> Any: | ||
""" | ||
Perform a PUT request and return the data. | ||
:arg url: absolute url (without host) to target | ||
:arg headers: dictionary of headers, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class | ||
:arg params: dictionary of query parameters, will be handed over to the | ||
underlying :class:`~opensearchpy.Connection` class for serialization | ||
:arg body: body of the request, will be serialized using serializer and | ||
passed to the connection | ||
""" | ||
return await self.transport.perform_request( | ||
"PUT", url=url, headers=headers, params=params, body=body | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.