It depends on what you are actually wanting to do.
encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it.
encodeURIComponent will encode everything with special meaning, so you use it for components of URIs such as:
const world = 'A string with symbols & characters that have special meaning?'
const uri = 'http://example.com/foo?hello=' + encodeURIComponent(world)
Answer from Quentin on Stack Overflowjavascript - Should I use encodeURI or encodeURIComponent for encoding URLs? - Stack Overflow
JavaScript's equivalent of encodeURIComponent() method in golang
Using encodeURIComponent and decodeURIComponent
encodeURIComponent and decodeURIComponent
It depends on what you are actually wanting to do.
encodeURI assumes that the input is a complete URI that might have some characters which need encoding in it.
encodeURIComponent will encode everything with special meaning, so you use it for components of URIs such as:
const world = 'A string with symbols & characters that have special meaning?'
const uri = 'http://example.com/foo?hello=' + encodeURIComponent(world)
If you're encoding a string to put in a URL component (a querystring parameter), you should call encodeURIComponent.
If you're encoding an existing URL, call encodeURI.
I have searched enough around the internet. But couldn't find a simple way to do the URL encoding.
In JavaScript we have a function called encodeURIComponent() which is very simple enough to use. But golang has ways to do the conversion. But it's not that simple.
Post your thoughts here, if you could help me out.
Usually, when I create a url for the fetch function I would use encodeURIComponent and on the backend decodeURIComponent on all params I receive. However, I noticed that this makes virtually no difference, as the params I receive on the backend always seem to be decoded. I noticed this because I thought that it would be convenient to write a middleware that does this but apparently this is already handled somehow. The thing is, I don't want to rely on features like this if I don't know where they are coming from and whether or not this behaviour is guaranteed. Do I need to use encodeURIComponent/decodeURIComponent? Where does it say so? I couldn't find anything on the docs about this. Maybe this doesn't even have anything to do with Next, idk