How to use reserved characters in a URI

If you have to encode a reserved character (such as ‘/’ or ‘@’) so that it can be passed in a URI path, you may need to encode it twice:

Example:

const ticker = '@SMC/2018',
	encodedTicker = encodeURIComponent(encodeURIComponent(ticker)),
	uri = `https://someexample.io/${encodedTicker}/load`;

See also: “When to Encode or Decode” if you like to be confused.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.