In my node.js App, I am consuming an API that accepts a call as follows
http://myapi.com/action?url= https://www.test.com/play?action=jump
Then based on the parameter passed into the URL parameter(example – ‘action=jump’) the API returns a specific response.
The problem I am experiencing is, in some cases, the URL sent to the API may already have a question mark with a query string(?song=portrait)
http://myapi.com/action?url= https://www.test.com/play?song=portrait?action=jump
In this case, the API is sending back the incorrect response because it’s using the very first question mark parameter from the query string. Example ?song=portrait
Without modifying the API how can I ensure that the API reads the parameter at the end - example – action=jump
Is there a way to escape the first question mark yet keeping a valid URL or how can I use url.format()
or url.parse()
to solve this problem
I forgot to add that I am already encoding the URL that is passed into the URL parameter.