NAME

Langertha::Role::HTTP - Role for HTTP APIs

VERSION

version 0.304

url

Base URL for API requests. Optional — many engines hard-code their default URL internally and only require this attribute to be set when pointing at a custom or self-hosted endpoint.

generate_json_body

my $body = $engine->generate_json_body(%args);

Encodes %args as a JSON string using the engine's "json" in Langertha::Role::JSON instance. Used internally when building application/json request bodies.

generate_multipart_body

my $body = $engine->generate_multipart_body($request, %args);

Encodes %args as a multipart/form-data body and attaches it to $request. Used internally when the OpenAPI spec specifies multipart/form-data content type (e.g. for audio upload endpoints).

generate_http_request

my $request = $engine->generate_http_request(
    $method, $url, $response_call, %args
);

Low-level HTTP request builder. Creates a Langertha::Request::HTTP object with the appropriate headers and body encoding (JSON or multipart). Calls the engine's update_request hook if it exists, allowing engines to inject authentication headers. If the URL contains user:password userinfo, HTTP Basic authentication is set automatically.

parse_response

my $data = $engine->parse_response($http_response);

Decodes a successful HTTP::Response body as JSON and returns the data structure. Croaks with the HTTP status line on failure. If the engine supports rate limiting, extracts rate limit headers via _update_rate_limit before decoding the body.

user_agent_timeout

Optional timeout in seconds for the LWP::UserAgent. When not set, the default LWP::UserAgent timeout applies.

user_agent_agent

The User-Agent string sent with HTTP requests. Defaults to the engine's class name.

user_agent

The LWP::UserAgent instance used for synchronous HTTP requests. Built lazily with user_agent_agent and user_agent_timeout.

execute_streaming_request

my $chunks = $engine->execute_streaming_request($request, $chunk_callback);
my $chunks = $engine->execute_streaming_request($request);

Executes a streaming HTTP request synchronously using LWP::UserAgent and delegates stream parsing to "process_stream_data" in Langertha::Role::Streaming. Requires the engine to also compose Langertha::Role::Streaming. Returns an ArrayRef of Langertha::Stream::Chunk objects. If $chunk_callback is provided it is called with each chunk as it is parsed.

SEE ALSO

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <torsten@raudssus.de> https://raudss.us/

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.