ExIconify.API (ExIconify v0.1.0)

View Source

Iconify API client for fetching SVG icons.

This module handles communication with the Iconify API to fetch icon SVGs. It supports all 100+ icon sets available on Iconify.

Configuration

You can configure the API settings:

config :ex_iconify,
  api_url: "https://api.iconify.design",  # Custom API endpoint
  api_timeout: 5_000                       # Request timeout in ms

Direct Usage

iex> ExIconify.API.fetch("lucide", "home")
{:ok, "<svg>...</svg>"}

iex> ExIconify.API.fetch("invalid", "icon")
{:error, :not_found}

Summary

Functions

Returns the configured API URL.

Checks if an icon exists without fetching the full SVG.

Fetches an icon SVG from the Iconify API.

Fetches multiple icons in a batch.

Functions

api_url()

@spec api_url() :: String.t()

Returns the configured API URL.

exists?(prefix, name)

@spec exists?(String.t(), String.t()) :: boolean()

Checks if an icon exists without fetching the full SVG.

Uses a HEAD request to check existence.

fetch(prefix, name)

@spec fetch(String.t(), String.t()) :: {:ok, String.t()} | {:error, term()}

Fetches an icon SVG from the Iconify API.

Parameters

  • prefix - The icon set prefix (e.g., "lucide", "mdi")
  • name - The icon name within the set (e.g., "home", "account")

Examples

iex> ExIconify.API.fetch("lucide", "home")
{:ok, "<svg xmlns=\"http://www.w3.org/2000/svg\" ...>...</svg>"}

iex> ExIconify.API.fetch("unknown", "icon")
{:error, :not_found}

fetch_batch(prefix, names)

@spec fetch_batch(String.t(), [String.t()]) :: %{
  required(String.t()) => {:ok, String.t()} | {:error, term()}
}

Fetches multiple icons in a batch.

Returns a map of icon names to their SVGs or errors.

Examples

iex> ExIconify.API.fetch_batch("lucide", ["home", "user", "settings"])
%{
  "home" => {:ok, "<svg>...</svg>"},
  "user" => {:ok, "<svg>...</svg>"},
  "settings" => {:ok, "<svg>...</svg>"}
}