URL Percent-Encoder & Decoder: RFC 3986 Standards & Query Safety
Safely encode and decode Uniform Resource Identifiers (URIs) using RFC 3986 percent-encoding to prevent broken query parameters and API request errors.
RFC 3986 Percent-Encoding Mechanics
URIs permit only a restricted subset of 66 unreserved ASCII characters (alphanumerics, hyphen, underscore, period, tilde). All other octets must be percent-encoded:
- Percent-Encoding Format: Characters are replaced with a percent sign (
%) followed by their two-digit hexadecimal ASCII/UTF-8 byte value (e.g. Space →%20,&→%26,=→%3D). - encodeURI vs. encodeURIComponent:
encodeURI()preserves protocol and path delimiters (/,:,?,#), whereasencodeURIComponent()encodes every reserved character, essential for passing full URLs as query parameters.
API Query Parameter Security & Web Scraping
Failing to encode query values causes server request parsers to truncate parameters prematurely when values contain ampersands (&) or question marks (?). Percent-encoding ensures clean HTTP transit across REST APIs and webhooks.
Pro Tip: Practical Application
Always use encodeURIComponent on values passed inside query strings (e.g. `?redirect=${encodeURIComponent(url)}`) to avoid parameter splitting.