Closed natalie-o-perret closed 6 months ago
using NodeJS Script should work.
{{
exports.ids=[
21720000,
21100000,
21100100,
21300000,
21200000,
21302000,
21310000,
24020500,
24020598
]
}}
GET {{apiHost}}/api/v1/entities
?{{ids.map(x => `id=${x}`).join('&')}}
You could rename your apiHost
variable to host
and just write GET /api/...
Multiple line variable definitions are really hard to parse without explicit end separator. Is a empty line or comment a end of variable definition or just some formatting modification. This parsing would be unstable. I would just use NodeJS Scripts for this use case.
Hey there @AnWeber, thanks for being responsive, you're amazing!
So about what you just suggested:
using NodeJS Script should work.
{{ exports.ids=[ 21720000, 21100000, 21100100, 21300000, 21200000, 21302000, 21310000, 24020500, 24020598 ] }} GET {{apiHost}}/api/v1/entities ?{{ids.map(x => `id=${x}`).join('&')}}
It kinda works, but there is some hiccup:
It works if the ?
query param prefix is one the same line as the host stuff, i.e.,
GET {{apiHost}}/api/v1/entities?{{ids.map(x => `id=${x}`).join('&')}}
leading effectively to (when evaluated by httpyac):
GET https://my-api.com/api/v1/entities?id=21720000&id=21100000&id=21100100&id=21300000&id=21200000&id=21302000&id=21310000&id=24020500&id=24020598
That being said, when it's on new line:
GET {{apiHost}}/api/v1/entities
?{{ids.map(x => `id=${x}`).join('&')}}
It ends being interpreted:
GET https://my-api.com/api/v1/entities
accept-encoding: gzip, deflate, br
accept: */*
content-length: 3458
user-agent: httpyac
?id=21720000&id=21100000&id=21100100&id=21300000&id=21200000&id=21302000&id=21310000&id=24020500&id=24020598
Authorization: Bearer my-amazingly-long-bearer-token
It's like the extra line messing things which oddly-enough isn't the case with the "Workaround 1: Full verbose variables" I mentioned in my original post, do you know what that might be the case?
Yes, I just noticed that too, the parser for the URL is probably not quite right. I'll have to have a look at the regex. One more addition, I also have a helper method that makes it easier to create query params, but it can only create arrays with the next release. I haven't needed it yet and am currently adding it.
{{
const {utils} = require("httpyac");
exports.q=utils.toQueryParams({ id: [
21720000,
21100000,
21100100,
21300000,
21200000,
21302000,
21310000,
24020500,
24020598
]})
}}
GET http://postman-echo.com/get?{{q}}
Yes, I just noticed that too, the parser for the URL is probably not quite right. I'll have to have a look at the regex. One more addition, I also have a helper method that makes it easier to create query params, but it can only create arrays with the next release. I haven't needed it yet and am currently adding it.
{{ const {utils} = require("httpyac"); exports.q=utils.toQueryParams({ id: [ 21720000, 21100000, 21100100, 21300000, 21200000, 21302000, 21310000, 24020500, 24020598 ]}) }} GET http://postman-echo.com/get?{{q}}
Nice! Can't wait ๐ชฉ๐!
I released a update containing these fixes.
๐โโ๏ธ Hello, it's again wee me!
Context
I have to deal some API (not mine), and the query params can pretty verbose I found only two ways to handle this case but none of them make things conveninent from my point of view:
Workarounds
Workaround 1: Full verbose variables
But as you can see, it's super verbose and time-consuming to type all the ids๐
Workaround 2: Nodejs script
So this works, but I see 2 main caveats:
Proposal
But it doesn't seem to work ๐ค
If something similar is already available, please feel free to point me towards that solution.
Also would love some support for multiple lines variable definitions, e.g.,
Wdyt?