Pedro Silva Pedro Silva - 1 month ago 5
Node.js Question

Paramethers with '/' in ExpressJS

I was wondering how to make a GET call passing a param that contains the '/' character. Is it possible?

Example:

GET /service/products/GIANAX W/22 cps


Thank you all very much!

Answer

Use encodeURIComponent on the piece of the URL that contains the / and use the resulting string as your actual URL.

For example, if you call encodeURIComponent() on "GIANAX W/22 cps" and combine it back with the other part of the URL, you will get:

/service/products/GIANAX%20W%2F22%20cps

Note, you can only call encodeURIComponent on one path segment at a time. You can't call it on the whole URL or otherwise it will escape the actual path separators that you want to retain.

Comments