Gopal S Akshintala
05/17/2022, 1:02 PMurlStr.urlEncoded()
is turning my URL into this: https%3A%2F%<http://2Fpokeapi.co|2Fpokeapi.co>%2Fapi%2Fv2%2Fpokemon%3Flimit%3D10
which is invalid. What’s the right and http4k idiomatic way to do it?s4nchez
05/17/2022, 1:04 PMGopal S Akshintala
05/17/2022, 1:06 PM{{baseUrl}}/services/data/v{{version}}/query/?q=SELECT Id FROM Profile where Name = 'Standard User'
I don’t wanna string replace spaces with %20
as there can be all types of urls with spl characters etc, so I wanna leverage encoderGopal S Akshintala
05/17/2022, 1:06 PMval uri = Uri.of(itemRequest.url.raw).let { it.query(it.query.urlEncoded()) }
I tried this, but it is replacing =
sign also which is causing a problem
like limit%3D10
s4nchez
05/17/2022, 1:11 PMUri.of("{{baseUrl}}/services/data/v{{version}}/query/")
.query("q", "SELECT Id FROM Profile where Name = 'Standard User'")
which translates to {{baseUrl}}/services/data/v{{version}}/query/?q=SELECT+Id+FROM+Profile+where+Name+%3D+%27Standard+User%27
Gopal S Akshintala
05/17/2022, 1:12 PMs4nchez
05/17/2022, 1:16 PMGopal S Akshintala
05/17/2022, 1:18 PMGopal S Akshintala
05/17/2022, 1:46 PMfun encodeUri(url: String): Uri =
Uri.of(url).let { uri ->
uri.queries().map { query -> query.first to query.second?.urlEncoded() }
.foldRight(uri) { encodedQuery, _ -> uri.query(encodedQuery.first, encodedQuery.second) }
}
s4nchez
05/17/2022, 3:50 PMjava.net.URI
to do that job and then converting to its various parts to org.http4k.Uri
Gopal S Akshintala
05/17/2022, 3:57 PMs4nchez
05/18/2022, 7:01 AMGopal S Akshintala
05/18/2022, 7:03 AMs4nchez
05/18/2022, 7:05 AMJames Richardson
05/18/2022, 10:49 AMquery/?q=SELECT%20Id%20FROM%20Profile%20where%20Name%20%3D%20'Standard%20User'
James Richardson
05/18/2022, 10:53 AMGopal S Akshintala
05/18/2022, 10:53 AMq
part and SELECT …
part first and encode only the value. The problem is with the split("=")
which returns the value as SELECT Id FROM Profile where Name
Gopal S Akshintala
05/18/2022, 10:55 AM'Standard User'
as there is an =
before thatJames Richardson
05/18/2022, 10:56 AMJames Richardson
05/18/2022, 10:56 AMGopal S Akshintala
05/18/2022, 10:57 AMJames Richardson
05/18/2022, 11:01 AMJames Richardson
05/18/2022, 11:03 AMGopal S Akshintala
05/18/2022, 11:03 AM{
"name": "Standard User Profile Query",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var statusCode = pm.response.code;",
"",
"var jsonData = JSON.parse(responseBody);",
"if(jsonData.records[0]!=null){",
" pm.environment.set(\"standardUserProfileId\", jsonData.records[0].Id);",
"}"
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{baseUrl}}/services/data/v{{version}}/query/?q=SELECT Id FROM Profile where Name = 'Standard User'",
"host": [
"{{baseUrl}}"
],
"path": [
"services",
"data",
"v{{version}}",
"query",
""
],
"query": [
{
"key": "q",
"value": "SELECT Id FROM Profile where Name = 'Standard User'"
}
]
}
},
"response": []
},
Gopal S Akshintala
05/18/2022, 11:04 AMJames Richardson
05/18/2022, 11:05 AMGopal S Akshintala
05/18/2022, 11:06 AMJames Richardson
05/18/2022, 11:06 AMJames Richardson
05/18/2022, 11:08 AMJames Richardson
05/18/2022, 11:41 AM=
🤷 - apologies - might have just thrown confusion into the mix.
encodeURIComponent
on javascript, and also some other encoding thing do, but postman doesn't. hmmmJames Richardson
05/18/2022, 12:15 PMs4nchez
05/22/2022, 11:55 AMGopal S Akshintala
05/22/2022, 12:04 PMgradle clean build
I get this: Dust.kt: (3, 12): Unresolved reference: nashorn
which might not be related to the change I dids4nchez
05/22/2022, 12:05 PMGopal S Akshintala
05/22/2022, 12:13 PM./gradlew clean build
succeed in my machines4nchez
05/22/2022, 12:14 PM