How to use reserved characters in a URI

Last Updated on September 19, 2018 by Colin

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:


const ticker = '@SMC/2018',
	encodedTicker = encodeURIComponent(encodeURIComponent(ticker)),
	uri = `${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.