diff options
author | Gene Pasquet <dev@etenil.net> | 2022-11-26 09:14:20 +0000 |
---|---|---|
committer | Gene Pasquet <dev@etenil.net> | 2022-11-26 09:14:20 +0000 |
commit | a55536340e16fcd9950aea3c04f474ed160b0ec9 (patch) | |
tree | 32b1625da7d562eecb58c3e4bbe55367783afe4b | |
parent | 2c0a9c413325ca512b481eaf1845ac4c6ec7ad59 (diff) |
-rw-r--r-- | README.md | 71 |
1 files changed, 50 insertions, 21 deletions
@@ -3,7 +3,8 @@ BARB  -Barb is a file-based API query tool that works nicely with version control and fits into UNIX terminal usage. +Barb is a file-based API query tool that works nicely with version +control and fits into UNIX terminal usage. <!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> @@ -32,13 +33,16 @@ Barb is a file-based API query tool that works nicely with version control and f ## Installation -Barb is only available through `Cargo` at this time. To install the default version with JSONPath only, [install rust with rustup](https://rustup.rs).do like so: +Barb is only available through `Cargo` at this time. To install the +default version with JSONPath only, [install rust with +rustup](https://rustup.rs).do like so: ``` cargo install barb ``` -If you'd like to have JQ filtering; ensure the `libjq` is installed on your machine, then run: +If you'd like to have JQ filtering; ensure the `libjq` is installed on +your machine, then run: ``` cargo install barb --features jq @@ -60,12 +64,14 @@ barb [options] <file 1> <file 2> ... <file n> - `-n, --no-color`: Don't use color output - `-f, --filter`: A JSON path to override any filters defined in the barb file - `-F, --no-filter`: Disable all filters (except for dependencies) -- `--hdr <HDR>`: Set/override a header with format `NAME=VALUE`, can appear multiple times (does not affect dependencies) +- `--hdr <HDR>`: Set/override a header with format `NAME=VALUE`, can + appear multiple times (does not affect dependencies) - `--help`: Displays the help page ## Barb format -Barb uses a custom file format to perform requests. Each file contains _one_ request and is started by a request preamble. Example: +Barb uses a custom file format to perform requests. Each file contains +_one_ request and is started by a request preamble. Example: ``` #POST^http://my-blog.com/posts @@ -79,11 +85,14 @@ Barb uses a custom file format to perform requests. Each file contains _one_ req ``` -The preamble contains the directives relevant to performing the request, such as the method, URL and headers. The preamble _must end with an empty line_. +The preamble contains the directives relevant to performing the +request, such as the method, URL and headers. The preamble _must end +with an empty line_. ### Verb line -The verb line indicates to _barb_ what sort of request to perform and where to. It follows this rigid format: +The verb line indicates to _barb_ what sort of request to perform and +where to. It follows this rigid format: ``` #<METHOD>^<URL> @@ -107,25 +116,32 @@ Headers are formatted as follows: #<HEADER NAME>: <HEADER VALUE> ``` -The `HEADER VALUE` supports variable substitution, `HEADER NAME` does not. +The `HEADER VALUE` supports variable substitution, `HEADER NAME` does +not. There can be none or many headers. ### Filter -Barb supports [JSONPath](https://goessner.net/articles/JsonPath/) filtering by default, and optionally JQ. +Barb supports [JSONPath](https://goessner.net/articles/JsonPath/) +filtering by default, and optionally JQ. #### JSONPath -Barb supports filtering of the response body with JSONPath. This has the following format: +Barb supports filtering of the response body with JSONPath. This has +the following format: ``` #$<JSON path> ``` -The `PATH` supports variable substitution. Refer to the [JSONPath](https://goessner.net/articles/JsonPath/) for more information on the filters and their syntax. +The `PATH` supports variable substitution. Refer to the +[JSONPath](https://goessner.net/articles/JsonPath/) for more +information on the filters and their syntax. -Filters can be named to populate execution variables by extracting values. Consider the following that will set the value of variable FOOBAR: +Filters can be named to populate execution variables by extracting +values. Consider the following that will set the value of variable +FOOBAR: ``` #FOOBAR$<JSON path> @@ -133,15 +149,20 @@ Filters can be named to populate execution variables by extracting values. Consi #### JQ -Barb supports JQ filtering of the response body. This has the following format: +Barb supports JQ filtering of the response body. This has the +following format: ``` #|<JQ FILTER> ``` -The `JQ FILTER` supports variable substitution. Refer to the [JQ manual](https://stedolan.github.io/jq/manual/#Basicfilters) for more information on the filters and their syntax. +The `JQ FILTER` supports variable substitution. Refer to the [JQ +manual](https://stedolan.github.io/jq/manual/#Basicfilters) for more +information on the filters and their syntax. -Filters can be named to populate execution variables by extracting values. Consider the following that will set the value of variable FOOBAR: +Filters can be named to populate execution variables by extracting +values. Consider the following that will set the value of variable +FOOBAR: ``` #FOOBAR|<JQ FILTER> @@ -149,7 +170,9 @@ Filters can be named to populate execution variables by extracting values. Consi ### Dependencies -A barb file can declare only _one_ dependency which will be executed before the main file is executed. If multiple dependencies are declared, only the last one will be executed. +A barb file can declare only _one_ dependency which will be executed +before the main file is executed. If multiple dependencies are +declared, only the last one will be executed. Syntax: @@ -157,13 +180,17 @@ Syntax: #>relative/path/to/file.barb ``` -The path to the dependency can either be relative to the current file or absolute. When running multiple barb files which have the same dependency, that dependency will only be executed _once_. +The path to the dependency can either be relative to the current file +or absolute. When running multiple barb files which have the same +dependency, that dependency will only be executed _once_. -A barb dependency _cannot have dependencies of its own_. Any dependency declared within a dependency will simply be ignored. +A barb dependency _cannot have dependencies of its own_. Any +dependency declared within a dependency will simply be ignored. ### Body -Anything after the preamble is considered as a body and will be send in the request for the following methods: +Anything after the preamble is considered as a body and will be send +in the request for the following methods: - PUT - POST @@ -173,7 +200,8 @@ Body does not support variable substitution. ### Variable substitution -Barb can include environment variable values and variables defined in `.env` into the requests with the following placeholder format: +Barb can include environment variable values and variables defined in +`.env` into the requests with the following placeholder format: #### Placeholder format @@ -198,7 +226,8 @@ GET http://127.0.0.1:8000/api/v1/status #### Default value -A placholder can be given a default value that will be used if the environment variable is not available. The format is as follows: +A placholder can be given a default value that will be used if the +environment variable is not available. The format is as follows: ``` {VARIABLE NAME:-DEFAULT} |