Caddy.Admin.Resources (Caddy v2.3.1)
View SourceDomain-specific helpers for common Caddy configuration paths.
Provides typed access to Caddy's JSON configuration structure, making it easier to work with apps, servers, routes, and TLS settings.
Examples
# Get all HTTP servers
{:ok, servers} = Caddy.Admin.Resources.get_http_servers()
# Add a route to a server
route = %{"match" => [%{"path" => ["/api/*"]}], "handle" => [...]}
{:ok, _} = Caddy.Admin.Resources.add_route("srv0", route)
# Get TLS configuration
{:ok, tls} = Caddy.Admin.Resources.get_tls()Caddy Config Structure
The typical Caddy JSON config structure:
%{
"admin" => %{"listen" => "unix//tmp/caddy.sock"},
"apps" => %{
"http" => %{
"servers" => %{
"srv0" => %{
"listen" => [":443"],
"routes" => [...]
}
}
},
"tls" => %{...}
}
}
Summary
Functions
Add a route to an HTTP server (appends to routes array).
Create a new HTTP server.
Delete a specific app.
Delete an HTTP server.
Delete a route at a specific index.
Get admin settings.
Get a specific app by name.
Get all configured apps.
Get a specific HTTP server by name.
Get all HTTP servers.
Get information about a PKI CA.
Get the certificate chain of a PKI CA.
Get a specific route by index.
Get all routes for an HTTP server.
Get TLS app configuration.
Get TLS automation configuration.
Get current status of reverse proxy upstreams.
Insert a route at a specific index.
Set admin settings.
Set or replace a specific app configuration.
Set or replace an HTTP server configuration.
Set TLS app configuration.
Set TLS automation configuration.
Update a route at a specific index.
Functions
Add a route to an HTTP server (appends to routes array).
Examples
route = %{
"match" => [%{"path" => ["/api/*"]}],
"handle" => [%{"handler" => "reverse_proxy", "upstreams" => [%{"dial" => "localhost:3000"}]}]
}
{:ok, _} = Caddy.Admin.Resources.add_route("srv0", route)
Create a new HTTP server.
Delete a specific app.
Delete an HTTP server.
@spec delete_route(String.t(), non_neg_integer()) :: :ok | {:error, term()}
Delete a route at a specific index.
Get admin settings.
Get a specific app by name.
Examples
{:ok, http_app} = Caddy.Admin.Resources.get_app("http")
{:ok, tls_app} = Caddy.Admin.Resources.get_app("tls")
Get all configured apps.
Returns the apps section of the Caddy config.
Get a specific HTTP server by name.
Examples
{:ok, server} = Caddy.Admin.Resources.get_http_server("srv0")
Get all HTTP servers.
Returns the servers map from the HTTP app.
Get information about a PKI CA.
Examples
{:ok, ca_info} = Caddy.Admin.Resources.get_pki_ca("local")
Get the certificate chain of a PKI CA.
@spec get_route(String.t(), non_neg_integer()) :: {:ok, map()} | {:error, term()}
Get a specific route by index.
Get all routes for an HTTP server.
Get TLS app configuration.
Get TLS automation configuration.
Get current status of reverse proxy upstreams.
This endpoint returns health status of configured upstream servers.
@spec insert_route(String.t(), non_neg_integer(), map()) :: {:ok, map()} | {:error, term()}
Insert a route at a specific index.
Set admin settings.
Set or replace a specific app configuration.
Set or replace an HTTP server configuration.
Set TLS app configuration.
Set TLS automation configuration.
@spec update_route(String.t(), non_neg_integer(), map()) :: {:ok, map()} | {:error, term()}
Update a route at a specific index.