
URL Encoding Explained: Why Your API Calls Break on Special Characters
I once spent an hour debugging an API integration that failed silently on certain user inputs. The search endpoint worked fine for "javascript" but returned empty results for "C++ programming." The culprit was the + character being interpreted as a space instead of a literal plus sign. The fix was one function call: encodeURIComponent() . But understanding why that fix works requires knowing how URL encoding actually operates. Why URLs need encoding URLs were designed in the early 1990s with a very limited character set. RFC 3986 defines the characters that can appear in a URL without encoding: letters, digits, and a handful of special characters ( - , _ , . , ~ ). Everything else -- spaces, non-ASCII characters, reserved delimiters -- must be percent-encoded. Percent encoding replaces each byte of a character with % followed by two hex digits representing that byte's value: Space -> %20 # -> %23 & -> %26 = -> %3D + -> %2B The reason is straightforward: characters like & , = , # , and
Continue reading on Dev.to JavaScript
Opens in a new tab

