Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

ain

> 开发工具
Open source

A HTTP API client for the terminal

623 stars0 likes0 views
WebsiteGitHub

About

A HTTP API client for the terminal

Introduction

Ain is a terminal HTTP API client. It's an alternative to postman, paw or insomnia.

  • Flexible organization of API:s using files and folders (examples).
  • Use shell-scripts and executables for common tasks.
  • Put things that change in environment variables or .env-files.
  • Handles url-encoding.
  • Share the resulting curl, wget or httpie command-line.
  • Pipe the API output for further processing.
  • Tries hard to be helpful when there are errors.

Ain was built to enable scripting of input and further processing of output via pipes. It targets users who work with many API:s using a simple file format. It uses curl, wget or httpie to make the actual calls.

⭐ Please leave a star if you find it useful! ⭐

Table of contents

  • Pre-requisites
  • Installation
    • If you have go installed
    • Via homebrew
    • Via scoop
    • Via the AUR (Arch Linux)
    • Download binaries yourself
  • Syntax highlight
    • Vim plug
  • Quick start
  • Important concepts
  • Template files
  • Running ain
  • Supported sections
    • [Host]
    • [Query]
    • [Headers]
    • [Method]
    • [Body]
    • [Config]
    • [Backend]
    • [BackendOptions]
  • Variables
  • Executables
  • Fatals
  • Quoting
  • Escaping
  • URL-encoding
  • Sharing is caring
  • Handling line endings
  • Troubleshooting
  • Ain in a bigger context
  • Contributing
    • Commit messages
    • Testing

Pre-requisites

You need curl, wget or httpie installed and available on your $PATH. To test this run ain -b. This will generate a basic starter template listing what backends are available on your system in the [Backend] section. It will select one and leave the others commented out.

You can also check manually what backends you have installed by opening a shell and type curl, wget or http (add the suffix .exe to those commands if you're on windows). Any output from the command means it's installed.

On linux or mac one of the three is likely to already be installed. The others are available in your package manager or homebrew.

If you're on windows curl.exe is installed if it's windows 10 build 17063 or higher. Otherwise you can get the binaries via scoop, chocolatey or download them yourself. Ain uses curl.exe and cannot use the curl cmd-let powershell builtin.

Installation

If you have go installed

You need go 1.13 or higher. Using go install:

go install github.com/jonaslu/ain/cmd/ain@latest

Via homebrew

Using the package-manager homebrew

bash
brew install ain

Via scoop

Using the windows package-manager scoop

scoop bucket add jonaslu_tools https://github.com/jonaslu/scoop-tools.git
scoop install ain

Via the AUR (Arch Linux)

From arch linux AUR using yay

yay -S ain-bin

Download binaries yourself

Install it so it's available on your $PATH: https://github.com/jonaslu/ain/releases

Syntax highlight

Ain comes with it's own syntax highlight for vim.

Vim plug

Using vim plug

Plug 'jonaslu/ain', { 'rtp': 'grammars/vim' }

Manual install

Quick start

Ain comes with a built in basic template that you can use as a starting point. Ain checks what backends (that's curl, wget or httpie) are available on your system and inserts them into the [Backend] section of the generated template. One will be selected and the rest commented out so the template is runnable directly.

Run:

ain -b basic-template.ain

The command above will output a starter-template to the file basic-template.ain. The basic template calls the / GET http endpoint on localhost with the Content-Type: application/json.

To run the template specify a PORT variable:

ain basic-template.ain --vars PORT=8080

See help for all options: ain -h and check out the examples.

Important concepts

  • Templates: Files containing what, how and where to make the API call. By convention has the file suffix .ain.
  • Sections: Label in a file grouping the API parameters.
  • Variables: Things that vary as inputs in a template file.
  • Executables: Enables using the output of a command in a template file.
  • Backends: The thing that makes the API call (curl, wget or httpie).
  • Fatals: Error in parsing the template files (it's your fault).

Template files

Ain assembles data in template files to build the API-call. Ain parses the data following labels called sections in each template file. Here's a full example:

…

The template files can be named anything but some unique ending-convention such as .ain is recommended so you can find them easily.

Ain understands eight [Sections] with each of the sections described in details below. The data in sections either appends or overwrites across template files passed to ain.

Anything after a pound sign (#) is a comment and will be ignored.

Running ain

ain [OPTIONS] [--vars VAR=VALUE ...]

Ain accepts one or more template-file(s) as a mandatory argument. As sections appends or overwrite you can organize API-calls into hierarchical structures with increasing specificity using files and folders.

You can find examples of this in the examples folder.

Adding an exclamation-mark (!) at the end of a template file name makes ain open the file in your $VISUAL or $EDITOR editor. If none is set it falls back to vim in that order. Once opened you edit the template file for this run only.

Example:

ain templates/get-blog-post.ain!     # Lets you edit the get-blog-post.ain for this run

Ain waits for the editor command to exit. Any terminal editor such as vim, emacs, nano etc will be fine. If your editor forks (as vscode does by default) check if there's a flag stopping it from forking. To stop vscode from forking use the --wait flag:

bash
export EDITOR="code --wait"

If ain is connected to a pipe it will read template file names from the pipe. This enables you to use find and a selector such as fzf to keep track of the template-files:

$> find . -name *.ain | fzf -m | ain

Template file names specified on the command line are read before names from a pipe. This means that echo create-blog-post.ain | ain base.ain is the same as ain base.ain create-blog-post.ain.

When making the call ain mimics how data is returned by the backend. After printing any internal errors of it's own, ain echoes back output from the backend: first the standard error (stderr) and then the standard out (stdout). It then returns the exit code from the backend command as it's own unless there are error specific to ain in which it returns status 1.

Supported sections

Sections are case-insensitive and whitespace ignored but by convention uses CamelCase and are left indented. A section cannot be defined twice in a file. A section ends where the next begins or the file ends.

See escaping If you need a literal section heading on a new line.

[Host]

Contains the URL to the API. This section appends lines from one template file to the next. This feature allows you to specify a base-url in one file (e g base.ain) as such: http://localhost:3000 and in the next template file specify the endpoint path (e g login.ain): /api/auth/login.

It's recommended that you use the [Query] section below for query-parameters as it handles joining with delimiters and trimming whitespace. You can however put raw query-parameters in the [Host] section too.

Any query-parameters added in the [Query] section are appended last to the URL. The whole URL is properly url-encoded before passed to the backend. The [Host] section must combine to one and only one valid URL. Multiple URLs is not supported.

Ain performs no validation on the url (as backends differ on what a valid url looks like). If your call fails use ain -p as mentioned in troubleshooting to see the resulting command.

The [Host] section is mandatory and appends across template files.

[Query]

All lines in the [Query] section is appended last to the resulting URL. This means that you can specify query-parameters that apply to many endpoints in one file instead of having to include the same parameter in all endpoints.

An example is if an API_KEY= query-parameter applies to several endpoints. You can define this in a base-file and simply have the specific endpoint URL and possible extra query-parameters in their own file.

Example - base.ain:

[Host]
http://localhost:8080/api

[Query]
API_KEY=a922be9f-1aaf-47ef-b70b-b400a3aa386e

get-post.ain

[Host]
/blog/post

[Query]
id=1

This will result in the url:

http://localhost:8080/api/blog/post?API_KEY=a922be9f-1aaf-47ef-b70b-b400a3aa386e&id=1

The whitespace in a query key / value is only significant within the string.

This means that page=3 and page = 3 will become the same query parameter and page = the next one will become page=the+next+one when processed. If you need actual spaces between the equal-sign and the key / value strings you need to encode it yourself: e g page+=+3 or put the key-value in the [Host] section where space is significant.

Each line under the [Query] section is appended with a delimiter. Ain defaults to the query-string delimiter &. See the [Config] section for setting a custom delimiter.

All query-parameters are properly url-encoded.

The [Query] section appends across template files.

[Headers]

Headers to pass to the API. One header per line.

Example:

[Headers]
Authorization: Bearer 888e90f2-319f-40a0-b422-d78bb95f229e
Content-Type: application/json

The [Headers] section appends across template files.

[Method]

Http method (e g GET, POST, PATCH). If omitted the backend default is used (GET in both curl, wget and httpie).

Example:

[Method]
POST

The [Method] section is overridden across template files.

[Body]

If the API call needs a body (as in the POST or PATCH http methods) the content of this section is passed as a file to the backend with formatting retained.

The file is removed after the API call unless you pass the -l flag. Ain places the file in the $TMPDIR directory (usually /tmp on your box). You can override this in your shell by explicitly setting the $TMPDIR environment variable.

Passing the print command -p flag will cause ain to write out the file named a

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goapiapi-clientapi-restcurl

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具