Skip to content

Commit

Permalink
doc: update book for v0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kriogenia committed Oct 7, 2024
1 parent e1b413a commit 96075ca
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 148 deletions.
33 changes: 18 additions & 15 deletions book/src/introduction.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# Rede

`rede` (galician word for "net") is a command-line utility to help run suites of requests to
ease the usage and testing of REST APIs. The main inspiration for this project comes from
[Bruno](https://www.usebruno.com/) and their command line tool.
`rede` (galician word for "net") is a command-line utility to help run suites
of requests to ease the usage and testing of REST APIs. The main inspiration
for this project comes from [Bruno](https://www.usebruno.com/) and their command
line tool.

The main goal behind this project is to have a suite of text files representing HTTP requests
that will be picked and executed by `rede`, allowing for easy sharing and control versioning
of these requests.
The main goal behind this project is to have a suite of text files representing
HTTP requests that will be picked and executed by `rede`, allowing for easy sharing
and control versioning of these requests.

![Execution of rede](./media/readme_rede.gif)

## Request DSL

Rede requests are stored as plain text files, so they can be easily stored and shared in your
project repositories via your favourite version control tool. You won't have to set a team with
your peers to have a shared suite of request to test your application, you only need to push those
files.
Rede requests are stored as plain text files, so they can be easily stored and
shared in your project repositories via your favourite version control tool.
You won't have to set a team with your peers to have a shared suite of request
to test your application, you only need to push those files.

The DSL that request used is based on TOML as it's a simple and human-readable format that matches
perfectly our needs. This is an example of a request that rede can execute.
The DSL that `rede` uses is based on TOML as it's a simple and human-readable
format that matches perfectly our needs. This is an example of a request that
rede can execute:

```toml
[http]
Expand All @@ -37,7 +39,8 @@ Pretty easy to digest, right?

## rede run

The main feature of `rede` is the command `run`. You can invoke with the name of the file of your
request and rede will execute it and return the results.
The main feature of `rede` is the command `run`. You can invoke it with the
name of the file of your request and rede will execute it and return the results.

![rede run with verbose](./media/readme_verbose.png)

![rede run with verbose](./media/readme_verbose.png)
18 changes: 11 additions & 7 deletions book/src/reference_guide/command_line_interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

The general way of running `rede` is using `rede <subcommand>`. The current supported
subcommands are:
- [run](./command_line_tool/run.md)
- [example](./command_line_tool/example.md)

- [run](./command_line_interface/run.md)
- [example](./command_line_interface/example.md)
- `help`, prints the help, same as `rede --help`.

`rede` supports infering for both, subcommands and arguments. That means that you substrings
can match a command as long as there's no conflict. For example, this is valid way of using
`rede run` with `--verbose`:
`rede` supports infering for both, subcommands and arguments. That means that
you can use substrings to match a command as long as there's no conflict. For
example, this is valid way of using `rede run` with `--verbose`:

```shell
rede r --verb my_request
Expand All @@ -17,7 +18,10 @@ rede r --verb my_request
## Global options

The following options of `rede` can be used with all subcommands.

- `--help`, will print the help of the respective command.
- `--quiet`, evades all standard output, only errors will be printed (to stderr).
- `--verbose`, ups the number of printing messages.
- `--quiet`, evades all standard output, only errors will be printed in stderr.
- `--dry-run`, _see for each command_.
- `--no-color`, disables coloring in the outputs.
- `--help`, will print the help of the respective command.

8 changes: 6 additions & 2 deletions book/src/reference_guide/command_line_interface/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This command is intended to give a brief help to people starting with
`rede`. In this first version using it will only output a message
with an example of a request- It will also create a file named `example.toml`
with an example of a request. It will also create a file named `example.toml`
with that request. This allows to have a valid request to try the `run` command.

```shell
Expand All @@ -11,4 +11,8 @@ rede run example
```

_This command is intended to provide example of different types of
features in the future, but right now it's limited to just this_
features in the future, but right now it's limited to just this_

Running this command with `--dry-run` will print the example message bad
it won't create the example file.

48 changes: 30 additions & 18 deletions book/src/reference_guide/command_line_interface/run.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# rede run

To execute requests in `rede` you need to use `rede run`. This command accepts a path to a file
containing a valid rede request. The `.toml` extension is optional, but rede will only attempt
to load files with that extension. By default, it will print the body of the response, or the
status code if there's no body in the response.
To execute requests in `rede` you need to use `rede run`.
This command accepts a path to a file containing a valid rede request.
The `.toml` extension is optional, but rede will only attempt to load
files with that extension. By default, it will print the body of
the response, or the status code if there's no body in the response.

```shell
rede run my_request
Expand All @@ -17,26 +18,37 @@ cat my_request | rede run > response.json

## Redirections

`rede run` will automatically follow redirect response to arrive at the pointed resource.
That means that unless this behavior is overriden `run` can't return 3xx responses. To
disable this behavior you can use the `--no-redirect` flag.
`rede run` will automatically follow redirect response to arrive at
the pointed resource. That means that unless this behavior is overridden
`run` can't return 3xx responses. To disable this behavior you can use
the `--no-redirect` flag.

On top of that, `run` will throw an error after 10 redirections followed in the same
request, you can override this value with `--max-redirects <value>`
On top of that, `run` will throw an error after 10 redirections
followed in the same request, you can override this value with `--max-redirects <value>`

## Verbosity

When using `rede run` with the different verbosity options this is what it will print (each
level will print the same as the previous plus what is described):
- `quiet`, will only print errors to stderr. The waiting spinner can show but it will be deleted.
When using `rede run` with the different verbosity options this is what
it will print (each level will print the same as the previous plus
what is described):

- `quiet`, will only print errors to stderr. The waiting spinner can show
but it will be deleted.
- `standard`, will print the response body. If it's empty, the response status code.
- `verbose`, will print the request that it's being sent (including headers and body) and the
whole response received (status, headers and body).
- `verbose`, will print the request that it's being sent (including headers and body)
and the whole response received (status, headers and body).

## Other options

`rede run` supports the following options:
- `--pretty-print`, specifies if formatting and jump lines should be applied to the response
body. It's enabled by default, but it can be disabled via `--pretty-print=false`
- `--timeout`, sets the maximum duration that the client should wait before giving a timeout.
For example, `--timeout 3s` to wait max 3 seconds.

- `--pretty-print`, specifies if formatting and jump lines should be
applied to the response body. It's enabled by default, but it can be disabled
via `--pretty-print=false`
- `--timeout`, sets the maximum duration that the client should wait before giving
a timeout. For example, `--timeout 3s` to wait max 3 seconds.

On top of that, it support the global `--dry-run` flag, this will execute all
the steps to build the request but won't execute it. It's a good way to test
your placeholders.

76 changes: 45 additions & 31 deletions book/src/reference_guide/request_dsl.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Request DSL

`rede` is built to work around [TOML](https://toml.io/en/) files modeling an HTTP request.
This is an example of a pretty complex HTTP request following `rede` DSL.
`rede` is built to work around [TOML](https://toml.io/en/) files modeling an
HTTP request. This is an example of a pretty complex HTTP request
following `rede` DSL.

```toml
[http]
Expand All @@ -16,7 +17,7 @@ author = "John Carmack"

[headers]
Content-Type = "multipart/form-data"
Authorization = "Bearer am6Mlw33eCVK"
Authorization = "Bearer {{BEARER_TOKEN}}"
Accept = "application/json"

[body.form_data]
Expand All @@ -25,22 +26,28 @@ description.text = "Just chilling killing some demons"
image.file = "~/Pictures/hell/ripping_living_heart_from_demon.png"
```

I could explain the request that is being represented there, but this format is so readable that there's no need.
We could explain the request that is being represented there, but this format
is so readable that there's no need.

# Tables
## Tables

Each table (`[table]`) represents a section of an HTTP request and inside each one a series of keys or tables can be
defined to provided all you need to represent the HTTP call.
Each table (`[table]`) represents a section of an HTTP request and inside each
one a series of keys or tables can be defined to provided all you need to
represent the HTTP call.

Some considerations applying to the whole schema:

- **Only `http` is required**, all the other tables are optional.
- The order is not relevant. The order used in this section is only for improve readability.
- Every valid TOML declaration is supported. There's no need to use the same as the examples here.
- The order is not relevant. The order used in this section is only to improve
readability.
- Every valid TOML declaration is supported. There's no need to use the same
as the examples here.
- Any multiword key supports `camel_case`, `lowercase` and `kebab-case`.

## [http]

This table accepts three possible keys:

- `url`, _string_. The only key **required** in the whole DSL.
- `method`, _string_. If omitted it will be `GET`. Accepts extension methods.
- `version`, _string_ of type `HTTP/x.y`. If omitted it will default to `HTTP/1.1`.
Expand All @@ -63,15 +70,15 @@ date = "1970-01-01"
My-Own_Weird_Header = "its valid tho"
```

_warning: some common leaders like `Host` and `Content-Type` will be autogenerated by
`rede` based on the other fields of the request. Future plans contemplate allowing the
option to disable this autogeneration_
_warning: some common headers like `Host` and `Content-Type` will be autogenerated
by `rede` based on the other fields of the request. Future plans contemplate
allowing the option to disable this autogeneration_

## [query_params]

This table is **free**. There's no predefined keys but the values can't be of type datetime
or tables. Arrays are supported and will be sent in the request as a comma separated list of
the values.
This table is **free**. There's no predefined keys but the values can't be of
type datetime or tables. Arrays are supported and will be sent in the request
as a comma separated list of the values.

```toml
[query-params]
Expand All @@ -82,9 +89,10 @@ tags = [ "dystopia", "space" ]

## [body]

The body is a table that can only contain **a single key** specifying the type of body and the
respective content of the body as value. Defining more than one body type would return an error.
The see all body types refer to [the body page](./request_dsl/body.md).
The body is a table that can only contain **a single key** specifying the type
of body and the respective content of the body as value. Defining more than
one body type would return an error. The see all body types refer
to [the body page](./request_dsl/body.md).

```toml
body.binary = "./doc/project_v2_final_final.pdf"
Expand All @@ -97,9 +105,10 @@ location = "unknown"
```

## [variables]
This table is **free**. There's no predefined keys but the values can't be of type datetime
or tables. Arrays are supported and will be sent in the request as a comma separated list of
the values.

This table is **free**. There's no predefined keys but the values can't be
of type datetime or tables. Arrays are supported and will be sent in
the request as a comma separated list of the values.

Variables serve to set a value to replace **placeholders** ([see](./request_dsl/placeholders.md)).

Expand All @@ -109,23 +118,28 @@ name = "Vin"
```

## [input_params]
The input params table can have any key desired by the user, but they must be tables. These tables
can be empty or can contain the following keys:

The input params table can have any key desired by the user, but they must
be tables. These tables can be empty or can contain the following keys:

- `hint`, _string_. A hint to the user when prompted to provide a value.
- `default`, _string_. The default value to be used if the user doesn't provide one.

```toml
[input_params]
host = { hint = "The host of the API", default = "127.0.0.1" }
id = { hint = "The ID of the resource" }
host = { hint = "The host of the API" }
id.hint = "The ID of the resource"
```

To know how the input parameters are used, refer to the [input parameters page](./request_dsl/input_parameters.md).

## [metadata]

This table is **free** but the values must be one of the primitive values (_string_, _integer_,
_float_ or _boolean_). It allows you to add any meaningful meta information. One key is currently
queried by `rede` but more could come in the future (for example, _description_):
- `name`. If present, `rede` will use it to refer to the request instead of using the filename.
_This works only for printing purposes, `rede run` still requires the filename.
This table is **free** but the values must be one of the primitive values
(_string_, _integer_, _float_ or _boolean_). It allows you to add
any meaningful meta information. One key is currently queried by `rede`
but more could come in the future (for example, _description_):

- `name`. If present, `rede` will use it to refer to the request instead of
using the filename.
_This works only for printing purposes, `rede run` still requires the filename.

Loading

0 comments on commit 96075ca

Please sign in to comment.