Skip to content

Commit

Permalink
docs: documents Steps API.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Dec 21, 2023
1 parent 9e27453 commit cc59018
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions docs/steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Steps

Imposter can perform multiple operations when it receives a request. These are called Steps. You can add multiple steps to a resource, calling external systems, running scripts and using [stores](./stores.md). Steps can use the output of other steps, as well as data from the request, or stores. The response can use the outputs of steps, such as in a [response template](./templates.md).

## Step Types

Imposter supports the following step types:

- Execute a script
- Make an HTTP(S) request to a server

> **Note**
> Steps are executed in the order they are defined in the configuration file.
### Simple example

Here is an example with a single step:

```yaml
# ...part of your configuration file

resources:
- path: /example
method: GET
steps:
- type: script
script: |
console.log('Hello World!');
```
### Multiple steps
Here is an example of a configuration file with multiple steps:
```yaml
# ...part of your configuration file

resources:
- path: /example
method: GET
steps:

# the first step will send an HTTP request to example.com
# and store its response status code and body in the 'current' object
- type: remote
url: http://example.com
method: GET
capture:
statusCode:
expression: "${remote.response.statusCode}"
responseBody:
expression: "${remote.response.body}"

# the second step will log the status code of the response
- type: script
script: |
console.log('Remote HTTP response status code: ' + current.statusCode);
response:
content: "${current.responseBody}"
```

0 comments on commit cc59018

Please sign in to comment.