jonaslu / ain

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

add support for base section #18

Closed adikari closed 1 year ago

adikari commented 1 year ago

Instead of having to run something like

ain base.ain some-request.ain

it would be good to be able to specify the base in the .ain file as a block.

Then we could simply run

ain some-request.ain

I am imagining the template would look something like this

[Base]
base.ain (or potentially path to the file)

[Host]
/api/blog/create

[Method]
POST

[Body]
{
  "title": "Million dollar idea",
  "text": "A dating service. With music."
}

Let me know if you would consider this as a feature. I am happy to implement this as a feature if you dont have time.

sandebert commented 1 year ago

I think this would be a somewhat better format. It would also more clearly communicate one can build a chain of ain files. (Because the base.ain file can itself contain a Require section, and so on.)

[Require]
base.ain
jonaslu commented 1 year ago

Out of curiosity, is there any other problem besides saving a few keystrokes you're trying to solve with this?

adikari commented 1 year ago

Saving a few keystrokes is the main goal. If I have 20 api endpoints that all share the same base, it is quite repetitive to add those key strokes.

My main concern is I have collections that extend different bases. Now it's quite a bit of cognitive overload to remember which ones extend which.

jonaslu commented 1 year ago

In the first case, you mean you have to type ain base.ain some-endpoint1.ain? I'd do that with either with an alias, or a script like ain base.ain $@

In the second one I'm not following, do you have all files in one big folder?

adikari commented 1 year ago

I have all my stuff in a single folder. I know we can do it with alias and all the fancy things. My ask was to see if we want to add the functionality in the config. If you don't want to, we can close the issue.

jonaslu commented 1 year ago

Ok, then it's a nope!

Folders, files, aliases and shell-scripts are far far more flexible for organizing things than ain would ever be