Skip to content

HttpSearchProvider

Category: Web

Source: http_search_provider.dart

Classes

SearchApiException

Error raised when a search provider's HTTP API returns a non-200 status.

Constructor

dart
SearchApiException(this.message)

Properties

PropertyTypeDescription
messageString

Methods

String toString()
static String truncateBody(String body)

Truncates an HTTP error body to the first 200 chars for safe inclusion in an exception message. Shared by every HTTP-backed search provider.

HttpSearchRequest

Describes a single HTTP request a search provider issues to its backend.

A non-null [body] implies a POST; a null [body] implies a GET.

Constructor

dart
HttpSearchRequest({required this.uri, required this.headers, this.body})

Properties

PropertyTypeDescription
uriUri
headersMap<String, String>
bodyString?

abstract HttpSearchProvider

Shared skeleton for API-key-backed HTTP search providers (Brave, Tavily, Firecrawl). Owns [isConfigured], the not-configured guard, the timeout, and the non-200 status check with 200-char body truncation.

Subclasses supply only [buildRequest] (request shape per query) and [parseResponseBody] (JSON → [WebSearchResponse]).

Constructor

dart
HttpSearchProvider({
    required this.apiKey,
    this.timeoutSeconds = 15,
    http.Client? client,
  })

Properties

PropertyTypeDescription
apiKeyString?
timeoutSecondsint
apiLabelString getHuman-readable provider label used in error messages (e.g. 'Brave Search API', 'Tavily API').
notConfiguredMessageString getError message used when [isConfigured] is false.
isConfiguredbool get
apiLabelString getHuman-readable provider label used in error messages (e.g. 'Brave Search API', 'Tavily API').
notConfiguredMessageString getError message used when [isConfigured] is false.
isConfiguredbool get

Methods

HttpSearchRequest buildRequest(String query, int maxResults)

Builds the HTTP request for [query] / [maxResults].

WebSearchResponse parseResponseBody(Map<String, dynamic> json, String query)

Maps a decoded JSON body to a [WebSearchResponse].

Future<WebSearchResponse> search(String query, {int maxResults = 5})

Released under the MIT License.