URL Encoder and Decoder in Go — Code Examples
URL encoding (percent-encoding) replaces characters that are not allowed in URLs with a percent sign followed by their hexadecimal value. Here is how to encode and decode URL components in each language.
Go's net/url package provides url.QueryEscape for query parameters and url.PathEscape for path segments.
package main
import (
"fmt"
"net/url"
)
func main() {
input := "hello world & foo=bar"
// Encode a query parameter value (spaces become +)
encoded := url.QueryEscape(input)
fmt.Println(encoded) // hello+world+%26+foo%3Dbar
// Decode
decoded, err := url.QueryUnescape("hello+world+%26+foo%3Dbar")
if err != nil {
panic(err)
}
fmt.Println(decoded) // hello world & foo=bar
// Encode a path segment (spaces become %20, / is encoded)
pathEncoded := url.PathEscape(input)
fmt.Println(pathEncoded) // hello%20world%20&%20foo=bar
// Build a query string
params := url.Values{}
params.Set("q", "hello world")
params.Set("page", "1")
fmt.Println(params.Encode()) // page=1&q=hello+world
}- QueryEscape encodes spaces as + (for query strings); PathEscape encodes them as %20 (for URL paths).
- url.Values.Encode() builds a sorted, encoded query string.
- Always handle the error from QueryUnescape — malformed percent sequences return an error.
Need to url encode/decode without writing code? The URL Encoder and Decoder runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.
Open URL Encode/Decode →URL Encoder and Decoder in JavaScript / Node.js
JavaScript has two pairs of functions: encodeURI/decodeURI for full URLs and encodeURIComponent/decodeURIComponent for individual query parameter values.
URL Encoder and Decoder in Python
Python's urllib.parse module provides quote() for encoding path segments, quote_plus() for form data, and urlencode() for building query strings.
URL Encoder and Decoder in Java
Use java.net.URLEncoder for encoding form parameters and java.net.URI for encoding full URLs.
URL Encoder and Decoder in PHP
PHP has urlencode() for form data (spaces as +) and rawurlencode() for URL path segments (spaces as %20). Use http_build_query() to build full query strings.
URL Encoder and Decoder in Ruby
Ruby provides CGI.escape for form-style encoding and URI.encode_www_form_component for query strings. Both are in the standard library.
URL Encoder and Decoder in Rust
Rust has the urlencoding crate for simple percent-encoding, and the url crate for full URL building and parsing.
URL Encoder and Decoder in C# / .NET
C# provides Uri.EscapeDataString for RFC 3986 encoding and WebUtility.UrlEncode for form-style encoding (spaces as +).