URL encoding


URL Encoding is a form of data encoding that is used in API calls to pass data within a query string. It is used to ensure valid URLs and data are passed between web applications and the server. When making a request to an API, the parameters included in the URL request may contain characters that have special meaning for the web server. URL encoding allows the browser or web server to safely transfer this data, as it converts all special characters and spaces into a format that web browsers can understand.

URL encoding works by replacing any characters or spaces in the URL with escape sequences of the form ‘%xx’, where ‘xx’ is a two-digit hexadecimal number which represents the equivalent character in the ASCII character set. For example, an URL encoding for the character ‘ ’ is ‘%20’, and for the character ‘#’ is ‘%23’.

An example of URL encoding in an API request is a URL containing a query string containing the characters ‘&’ and ‘=’:


The ‘&’ and ‘=’ characters have special meaning in URLs, so they need to be encoded. The query string in the URL above is encoded to be:


This encoding is necessary to ensure that the web server correctly interprets the data being passed and to ensure that any special characters are handled correctly.

URL encoding can be thought of as a way of digitally packaging data before it is sent to an API, in much the same way that gift wrapping is used to protect a present before it is sent. This ensures that the data is properly interpreted and safely transmitted to the web server.