What does the URL Encoder do?
The URL Encoder converts reserved URI characters (spaces, ampersands, question marks, equals signs, slashes, colons, and hash marks) into UTF-8 percent-encoded hexadecimal sequences (e.g. %20 or +) adhering strictly to RFC 3986 and WHATWG URL specifications.
Core Concepts
Understanding URL percent-encoding rules:
- Percent-Encoding (RFC 3986): Converts reserved and non-ASCII characters into
%followed by their two-digit hexadecimal UTF-8 byte representation (such as%2Ffor/and%3Ffor?). - Space Encoding Options: Supports standard RFC 3986 percent-encoding (
%20) andapplication/x-www-form-urlencodedplus-character format (+). - Query Parameter Safety: Prevents delimiter collision when passing complex nested values, tokens, and filenames within HTTP GET query strings.
How to use the tool?
- Enter URL or Query: Paste your raw web address, query parameter, or text string into the editor or click Load Sample.
- Configure Space Encoding: Optionally check Encode spaces as plus (+) instead of %20.
- Encode & Copy: Click Encode URL String, then click Copy or Download to export the encoded URI string.
Related Developer Utilities
If you work with web URLs, HTTP parameters, and entity encodings, explore these complementary tools:
- URL Decoder: Decode percent-encoded URLs and query parameters.
- HTML Entity Encoder: Convert reserved HTML characters into XML/HTML entities.
- HTML Entity Decoder: Unescape HTML character entities into clean UTF-8 text.
- Base64 Encoder: Encode plain text and binary strings into Base64 format.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/url/url-encoder) to programmatically percent-encode URLs and query parameter strings.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Raw URL or query string to percent-encode. | "https://blueutils.com/search?q=hello world" |
options.encodeSpaceAsPlus |
Boolean | Optional. Encode spaces as + instead of %20. Default: false. |
false |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/url/url-encoder \
-H "Content-Type: application/json" \
-d '{
"rawText": "https://blueutils.com/search?q=hello world",
"options": { "encodeSpaceAsPlus": false }
}'Python
import requests
url = "https://blueutils.com/api/url/url-encoder"
payload = {
"rawText": "https://blueutils.com/search?q=hello world",
"options": {"encodeSpaceAsPlus": False}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "https://blueutils.com/search?q=hello world",
"options": { "encodeSpaceAsPlus": false }
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/url/url-encoder"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether encoding succeeded. | true |
input |
String | Echoes the input URL payload. | "https://blueutils.com/search?q=hello world" |
encodedText |
String | Percent-encoded URL string. | "https%3A%2F%2Fblueutils.com%2Fsearch%3Fq%3Dhello%20world" |
output |
String | Encoded URL result string. | "https%3A%2F%2Fblueutils.com%2Fsearch%3Fq%3Dhello%20world" |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"input": "https://blueutils.com/search?q=hello world",
"encodeSpaceAsPlus": false,
"encodedText": "https%3A%2F%2Fblueutils.com%2Fsearch%3Fq%3Dhello%20world",
"output": "https%3A%2F%2Fblueutils.com%2Fsearch%3Fq%3Dhello%20world"
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid input: URL payload to encode cannot be empty."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to encode URLs?
Integrating the URL Encoder API into automated web scrapers, crawler jobs, or AI agent tool calling provides key benefits:
- Rapid Script Validation: Percent-encodes dynamic search parameters and redirect URLs before making HTTP network requests.
- Optimized Token Efficiency for AI Agents: LLMs frequently miscalculate multi-byte UTF-8 percent sequences. Calling the API encodes special characters deterministically without token hallucinations.
- Deterministic Accuracy Without Hallucinations: Ensures 100% compliant RFC 3986 character escaping.
Native Usage
How to percent-encode URLs locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Percent-encode URL string in PowerShell
[System.Uri]::EscapeDataString('https://blueutils.com/search?q=hello world')Linux / Unix (Bash)
# Percent-encode URL string using jq in Linux
jq -rn --arg x "https://blueutils.com/search?q=hello world" '$x | @uri'Python
Using Python urllib.parse:
import urllib.parse
raw_url = "https://blueutils.com/search?q=hello world"
encoded = urllib.parse.quote(raw_url, safe='')
print("Encoded:", encoded)Java
Using Java URLEncoder:
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class UrlEncoderExample {
public static void main(String[] args) throws Exception {
String raw = "https://blueutils.com/search?q=hello world";
String encoded = URLEncoder.encode(raw, StandardCharsets.UTF_8.toString());
System.out.println("Encoded: " + encoded);
}
}