Skip to content

Commit

Permalink
docs: add library example for HTTP API
Browse files Browse the repository at this point in the history
  • Loading branch information
typpo committed May 30, 2024
1 parent 790fd4c commit 1705de0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions site/docs/providers/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ tests:

If not specified, HTTP POST with content-type application/json is assumed.

## Parsing a JSON response

If your API responds with a JSON object and you want to pick out a specific value, use the `responseParser` property to set a Javascript snippet that manipulates the provided `json` object.

For example, this `responseParser` configuration:
Expand Down Expand Up @@ -79,4 +81,27 @@ Extracts the message content from this response:
}
]
}
```

## Using as a library

If you are using promptfoo as a [node library](/docs/usage/node-package/), you can provide the equivalent provider config:

```js
{
// ...
providers: [{
id: 'https://example.com/generate',
config: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: {
foo: '{{bar}}',
},
responseParser: (json) => json.output,
}
}],
}
```

0 comments on commit 1705de0

Please sign in to comment.