jonaslu / ain

A HTTP API client for the terminal
MIT License
592 stars 13 forks source link

Multiple endpoint in same ain file #15

Closed mikhi-nde closed 2 years ago

mikhi-nde commented 2 years ago

Hi. hope you are fine. :)

Is there a way to run the same query on multiple endpoint for example:

curl -XDELETE http://elastisearch.local/index_1 curl -XDELETE http://elastisearch.local/index_2 curl -XDELETE http://elastisearch.local/index_3

btw. thank you for this awesome tool.

jonaslu commented 2 years ago

Hi, thanks for your kind words!

Not sure I'm following - do you mean having several url:s in the same file? Or do you mean re-using all but the {1,2,3} in the url?

jonaslu commented 2 years ago

A week without any interaction means closing. Re-open if you're still interested.

mikhi-nde commented 2 years ago

Hello @jonaslu

I was busy lately.

I mean having several urls in the same file, in the [host] section

jonaslu commented 2 years ago

No problems...

The focus of ain is one URL per invocation. The problem with several URLs in the same file is when you combine that file with more files using ains cascading features. If there is two urls in the first file, then how do I know how to combine the rest of the [Host]` sections in the succeding files? I've not yet come up with a decent solution for this that's not overly complex.

It's fairly easy to script around invoking it several times, in your specific case you could do something like:

$> cat base.ain
[Host]
http://elastisearch.local/index_${INDEX}

[Method]
DELETE

[Backend]
curl
for i in {1..3}; do INDEX=$i ain -p base.ain; done

You could even generalize have all the URLs in a separate file and using xargs:

$> cat base.ain
[Host]
${URL}

[Method]
DELETE

[Backend]
curl
cat urls.txt | xargs -I% bash -c 'URL=%; ain -p base.ain'