0

I need to pass the below string to a GET API method call. However since the string has a %in it, it becomes a bad url. How do I achieve this?

I have a query json

var world = JSON.stringify(query);

console.log(world);

Output:

{ "world" : "keyvalue" : { "data" : {"key" : "hundred","value" : "100%"} } }

I then pass this to the API as below

var uri = '../api/hello_world/test/' + world;

API call:

 server.route ({
    path: '/api/hello_world/test/{text*}',
    method: 'GET',
    handler: async function (req, reply) {
    console.log(req)
    ... 

The request is not getting sent to the API as the url becomes invalid with %%22 - %22 for "

I tried encoding with encodeURI(world) and the url now has %25%22. The request seems to be invalid here as well.

Not sure how to resolve this. Any help is appreciated.

pouyan
  • 3,445
  • 4
  • 26
  • 44
fledgling
  • 991
  • 4
  • 25
  • 48

0 Answers0