BraveEx is an Elixir client library for interacting with the Brave Search API. It provides a simple and consistent interface to perform web, image, video, news searches, fetch query suggestions, and perform spellchecks—all using a unified API.
- Web Search: Quickly perform standard web searches.
- Image Search: Retrieve image search results.
- Video Search: Get video search results.
- News Search: Access the latest news results.
- Query Suggestions & Spellcheck: Enhance your search experience with suggestions and spellchecking.
Add brave_ex
to your list of dependencies in mix.exs
:
def deps do
[
{:brave_ex, "~> 0.1.0"}
]
end
Then, fetch the dependencies by running:
mix deps.get
BraveEx requires an API key for authenticating with the Brave Search API. The API key is determined via the following priority:
- Passed in explicitly as an option (
:api_key
). - Pulled from the environment variable
BRAVE_API_KEY
. - Retrieved from your application configuration (default app key is
:brave_ex
).
Make sure your API key is set in one of these ways before using the library.
All search functions accept a query string and an optional keyword list of parameters to customize the search request.
iex> BraveEx.web_search("Elixir programming")
-
Image Search
iex> BraveEx.image_search("Elixir logo")
-
Video Search
iex> BraveEx.video_search("Elixir tutorial")
-
News Search
iex> BraveEx.news_search("Elixir release")
-
Query Suggestions
iex> BraveEx.get_query_suggestion("Elixir")
-
Spellcheck
iex> BraveEx.spellcheck("Elixr")
Each search function accepts an optional keyword list that lets you override default values and customize your request. Some of the common options include:
-
:base_url
The base URL for the Brave API.
Default:https://api.search.brave.com/res/v1
-
:timeout
Request timeout in milliseconds.
Default:10_000
-
:api_key
Your Brave API key. If not provided, it will be fetched from the environment or config. -
:app
The application name used when fetching the API key from configuration.
Default::brave_ex
-
:country
The country code for the search.
Default:"US"
-
:search_lang
The search language preference.
Default:"en"
-
:ui_lang
The user interface language for the response (e.g.,"en-US"
).
Default:"en-US"
-
:count
The number of search results returned.
Default:20
-
:offset
Pagination offset for search results.
Default:0
-
Other options include
:safesearch
,:freshness
,:text_decorations
,:spellcheck
,:result_filter
,:goggles
,:units
,:extra_snippets
, and:summary
.
For full details, please refer to the function documentation inside the module.
Contributions are welcome! If you’d like to help improve BraveEx, feel free to fork the repository and submit pull requests. For any major changes, please open an issue first to discuss what you would like to change.
BraveEx is released under the BSD-3-Clause License.