Skip to main content
The format_url function constructs a properly formatted URL from a dynamic object containing URL components (scheme, host, path, port, etc.). Use this function when you need to build URLs programmatically from parsed components or when reconstructing URLs from log data.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, you typically concatenate URL parts manually with eval. APL’s format_url provides a structured approach.
| eval full_url=scheme."://".host.":".port.path
In ANSI SQL, URL formatting requires string concatenation with null handling. APL’s format_url simplifies this operation.
SELECT CONCAT(scheme, '://', host, COALESCE(CONCAT(':', port), ''), path) AS url FROM logs;

Usage

Syntax

format_url(url_parts)

Parameters

NameTypeRequiredDescription
url_partsdynamicYesA dynamic object containing URL components: scheme, host, path, port, fragment, user, password, query.

Returns

Returns a properly formatted URL string constructed from the provided components.

Use case examples

  • Log analysis
  • OpenTelemetry traces
  • Security logs
Reconstruct full URLs from parsed components to analyze complete request patterns.Query
['sample-http-logs']
| extend full_url = format_url(dynamic({'scheme': 'https', 'host': 'api.example.com', 'path': uri}))
| project _time, method, status, full_url
| limit 10
Run in PlaygroundOutput
_timemethodstatusfull_url
2024-11-06T10:00:00ZGET200https://api.example.com/api/users
2024-11-06T10:01:00ZPOST201https://api.example.com/api/orders
2024-11-06T10:02:00ZGET200https://api.example.com/api/products
This query reconstructs full URLs from URI paths by adding the scheme and host, useful for generating clickable links in reports.
  • parse_url: Parses a URL string into its components. Use this to reverse the formatting operation and extract URL parts.
  • parse_urlquery: Parses URL query parameters. Use this when you need to work with query string parameters specifically.
  • url_encode: Encodes a string for safe use in URLs. Use this to encode individual URL components before formatting.
  • strcat: Concatenates strings. Use this for simple URL construction without the structure of format_url.