darcyai.output.rest_api_stream
RestApiStream Objects
class RestApiStream(OutputStream)
A stream that sends data to a REST API.
Arguments
- url (
str
): The URL of the REST API. - method (
str
): The HTTP method to use. Must be one of 'POST', 'PUT', 'PATCH'. Defaults toPOST
. - content_type (
str
): The content type of the data. Must be one of 'json' or 'form'. Defaults tojson
. - headers (
dict
): The headers to send with the request. Defaults toNone
.
Examples
>>> from darcyai.output.rest_api_stream import RestApiStream
>>> rest_api_stream = RestApiStream(url="http://localhost:5000/api/v1/data",
method="POST",
content_type="json")
headers={"Authorization": "Bearer ..."})
write
def write(data: Any) -> Response
Processes the data and writes it to the output stream.
Arguments
- data (
Any
): The data to be written to the output stream.
Returns
Response
: The response from the REST API.
Examples
>>> from darcyai.output.rest_api_stream import RestApiStream
>>> rest_api_stream = RestApiStream(url="http://localhost:5000/api/v1/data",
method="POST",
content_type="json")
headers={"Authorization": "Bearer ..."})
>>> response = rest_api_stream.write({"data": "some data"})
close
def close() -> None
Closes the output stream.