url_encode function converts a string into a format that can be safely transmitted over the Internet by encoding special characters. Use this function to prepare strings for URLs, build query parameters, or ensure data integrity in web requests.
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.Splunk SPL users
Splunk SPL users
In Splunk SPL, you use
urlencode. APL’s url_encode provides the same functionality.ANSI SQL users
ANSI SQL users
In ANSI SQL, URL encoding varies by database. APL’s
url_encode provides standardized URL encoding.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| url | string | Yes | The input string to encode for URL transmission. |
Returns
Returns the string with special characters encoded for safe URL transmission.Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Encode log field values for safe inclusion in generated URLs or API calls.QueryRun in PlaygroundOutput
This query encodes search terms for safe use in API URLs, ensuring special characters don’t break the URL structure.
| _time | search_term | encoded_search | api_url |
|---|---|---|---|
| 2024-11-06T10:00:00Z | hello world & special chars | hello%20world%20%26%20special%20chars | /api/search?q=hello%20world%20%26%20special%20chars |
List of related functions
- url_decode: Decodes URL-encoded strings. Use this to reverse the encoding operation.
- format_url: Formats URLs from components. Use this for building complete URLs from parts.
- parse_url: Parses URLs into components. Use this to extract parts before encoding.
- base64_encode_tostring: Encodes strings as Base64. Use this for Base64 encoding rather than URL encoding.