jonaslu / ain

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

How you can send parameters in GET requests? #9

Closed ericktucto closed 2 years ago

ericktucto commented 2 years ago

Please can you send a section where you can add the parameters that are GET requests

example

[Method]
GET
[Params]
page: 3

imagen

jonaslu commented 2 years ago

I'm not sure I follow, do you mean /api/v2/todos?page=3, so the page: 3 would turn into page=3?

ericktucto commented 2 years ago

Currently sending the parameters that way /api/v2/todos?page=3 , create this issue as a proposal to separate the endpoint from the sent parameters

jonaslu commented 2 years ago

Ok. I've thought about this some. In the one-file case it's not worth introducing a new section as you actually need to type more. But in the cascading case where you have base-files and more specific files for different endpoints it does makes sense.

An example is where you need to pass an API_KEY= to a bunch of endpoints as a query parameter. Since URL:s currently combine you need to specify that API_KEY in each of the last files pased to ain to get it in as a query-parameter. This leads to duplication.

If there was a [QueryParams] section that would also combine, but be placed after the first ? then it could be specified in a base-file and not duplicated.

Same goes for any fragment in the URL.

I'll flesh out the details in the coming days.

jonaslu commented 2 years ago

So, I've added a [Query] section in ain v1.2.0. You can read up on the syntax here: https://github.com/jonaslu/ain#query

Note that parameters are written as they would be in an url with an equals sign (and whitespace within the key is significant):

page=3

It turns out i TIL that fragments are a client-side thing only and curl, wget and httpie ignores any fragment in the url, so I won't be doing those in the same way.

jonaslu commented 2 years ago

Oh, and thanks for the input.. :+1:

ericktucto commented 2 years ago

Thank you very much for including the new [Query] section 😀

jonaslu commented 2 years ago

No problem. I changed so whitespace is not significant in the [Query] section in version v1.2.1

So these two are the same in v1.2.1 and onwards:

page=3
page = 3
ericktucto commented 2 years ago

excellent, now i update ain