format_url
This page explains how to use the format_url function in APL.
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.
Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| url_parts | dynamic | Yes | A 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
Reconstruct full URLs from parsed components to analyze complete request patterns.
Query
Output
| _time | method | status | full_url |
|---|---|---|---|
| 2024-11-06T10:00:00Z | GET | 200 | https://api.example.com/api/users |
| 2024-11-06T10:01:00Z | POST | 201 | https://api.example.com/api/orders |
| 2024-11-06T10:02:00Z | GET | 200 | https://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.
Build URLs from trace attributes to identify the full endpoints being called.
Query
Output
| _time | service.name | service_url | trace_id |
|---|---|---|---|
| 2024-11-06T10:00:00Z | frontend | http://localhost:8080/frontend | abc123 |
| 2024-11-06T10:01:00Z | checkout | http://localhost:8080/checkout | def456 |
| 2024-11-06T10:02:00Z | cart | http://localhost:8080/cart | ghi789 |
This query constructs service URLs from trace data, helping visualize the actual endpoints in a distributed system.
Construct URLs with authentication parameters to audit access attempts.
Query
Output
| _time | access_url | status | geo.country |
|---|---|---|---|
| 2024-11-06T10:00:00Z | https://user123@secure.example.com/admin | 403 | United States |
| 2024-11-06T10:01:00Z | https://user456@secure.example.com/api/secret | 401 | Unknown |
This query constructs complete URLs including user information for failed authentication attempts, helping security teams understand the full context of access attempts.
List of related functions
- 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.