Hello to all my dear friends!
We have seen certain characters at times in the URL like “%3D” or “%20” or “%26”. Now it is important to know what are these.
Let us understand what are these characters.
A URL is of the form https://thestorywire.com. But at times URL also consists of space or double quote (“) or single quote (‘) or and symbol (&) or equals (=) symbol. Therefore to have proper and safe transfer or data to web server, browser encodes such special characters.
UTF-8 is the common character encoding standard used to encode special characters for a safe electronic transmission. UTF-8 stands for Unicode Transformation Format 8 bit. Almost every webpage on the internet is stored as UTF-8 encoded. It succeeds the ASCII character encoding.
So a URL of the form https://thestorywire.com?param=value is encoded as:
https%3A%2F%2Fthestorywire.com%3Fparam%3DvalueA quick handy command line tool to encode URL on linux is to use jq.
printf %s 'https://thestorywire.com?param=value' | jq -sRr @uri
                                                                                             
https%3A%2F%2Fthestorywire.com%3Fparam%3DvalueThe colon (:), slash (/), question mark (?), equal to (=) all special characters are encoded.
URL encoding replaces unsafe character with a percent (%) symbol followed by two hexadecimal digits.
Commonly Encoded Characters in URL
| Character | UTF-8 encoded character | 
| : | %3A | 
| / | %2F | 
| ? | %3F | 
| = | %3D | 
| blank space | %20 | 
| & | %26 | 
| Single quote (‘) | %27 | 
| Double quote (“) | %22 | 
Javascript Function to Encode and Decode URL
Apart from the quick command line tool shared above, javascript has functions to encode and decode url.
const url = "https://thestorywire.com?param=value" 
const encodedURI = encodeURIComponent(url) // Outputs https%3A%2F%2Fthestorywire.com%3Fparam%3Dvalue
console.log(encodedURI) // Outputs https%3A%2F%2Fthestorywire.com%3Fparam%3Dvalueconst decodedURI = decodeURIComponent(encodedURI)
console.log(decodedURI) // Outputs https://thestorywire.com?param=value