Skip to content

Commit c227005

Browse files
committed
Add an example on how to post XML data that is pulled from an XMl file.
Signed-off-by: Tim Beermann <[email protected]>
1 parent e8bba5a commit c227005

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/scripting/xml-example.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Posting an XML body
2+
3+
If you are posting against XML APIs it might be easier for you to get the XML directly from an XML file instead of posting its content into the _Form URL Encoded_ fields.
4+
5+
To enable file system access with bruno, you have to enable a setting within the collections `bruno.json` file:
6+
7+
```json
8+
{
9+
"version": "1",
10+
"name": "my-collection",
11+
"type": "collection",
12+
"scripts": {
13+
"filesystemAccess": {
14+
"allow": true
15+
}
16+
}
17+
}
18+
```
19+
20+
Besides that, just use a similar script like this one to pull data from your XML file that resides right next to your _.bru_ file:
21+
22+
```javascript
23+
const fs = require("fs");
24+
const path = require("path");
25+
26+
const attachmentFilename = "some.xml";
27+
const attachmentPath = path.join(bru.cwd(), attachmentFilename);
28+
const attachment = fs.readFileSync(attachmentPath);
29+
30+
req.setBody({"MyServiceXmlrequest": attachment.toString()});
31+
```

docs/table-of-contents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [External Libraries](/scripting/external-libraries)
3232
- [Sync Requests](/scripting/sync-requests)
3333
- [JavaScript Reference](/scripting/javascript-reference)
34+
- [XML Post Examle](/scripting/xml-example)
3435

3536
## Testing
3637

0 commit comments

Comments
 (0)