1

I have faced a problem with providing param into GET method. I have the next URL

https://test.com/api/v1/account/?include[]=tickers&include[]=holdings&include[]=views

How to provide parameter along with empty square brackets as param in GET method in my example? I saw https://github.com/karatelabs/karate/blob/master/karate-demo/src/test/java/demo/search/dynamic-params.feature , but didnt find my solution(

Holgar
  • 91
  • 5

1 Answers1

0

If you see Karate encoding it as %5B%5D that is actually the correct behavior: https://stackoverflow.com/a/59977660/143475

You can actually try this on httpbin.org and see for yourself that the server is able to decode it correctly. If your server cannot, it is most likely a bug.

* url 'https://httpbin.org/anything'
* param include[] = 'tickers'
* method get

See server response:

1 > GET https://httpbin.org/anything?include%5B%5D=tickers
1 > Host: httpbin.org
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
1 > Accept-Encoding: gzip,deflate


17:17:10.925 [main]  DEBUG com.intuit.karate - response time in milliseconds: 1528
1 < 200
1 < Date: Tue, 07 Feb 2023 11:47:10 GMT
1 < Content-Type: application/json
1 < Content-Length: 436
1 < Connection: keep-alive
1 < Server: gunicorn/19.9.0
1 < Access-Control-Allow-Origin: *
1 < Access-Control-Allow-Credentials: true
{
  "args": {
    "include[]": "tickers"
  }, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept-Encoding": "gzip,deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Apache-HttpClient/4.5.14 (Java/17.0.6)", 
    "X-Amzn-Trace-Id": "Root=1-63e23a3e-4004ea8e65dba95003ec150e"
  }, 
  "json": null, 
  "method": "GET", 
  "url": "https://httpbin.org/anything?include[]=tickers"
}

That said you can move everything to the URL:

* url `https://httpbin.org/anything?include[]=tickers`
* method get

And if you still need to parameterize things, you can, see: https://stackoverflow.com/a/75061809/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • 1
    * url `https://httpbin.org/anything?include[]=tickers` can't use in my case because I have dynamic value in url. But param include[] = 'tickers' works for me. Tnx. – Holgar Feb 07 '23 at 12:46
  • @Holgar great. the last link I provided shows how you can still have dynamic values in the URL – Peter Thomas Feb 07 '23 at 13:29