Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example on how to post XML data that is pulled from an XMl file. #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/scripting/xml-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Posting an XML body

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.

To enable file system access with bruno, you have to enable a setting within the collections `bruno.json` file:

```json
{
"version": "1",
"name": "my-collection",
"type": "collection",
"scripts": {
"filesystemAccess": {
"allow": true
}
}
}
```

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:

```javascript
const fs = require("fs");
const path = require("path");

const attachmentFilename = "some.xml";
const attachmentPath = path.join(bru.cwd(), attachmentFilename);
const attachment = fs.readFileSync(attachmentPath);

req.setBody({"MyServiceXmlrequest": attachment.toString()});
```
1 change: 1 addition & 0 deletions docs/table-of-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [External Libraries](/scripting/external-libraries)
- [Sync Requests](/scripting/sync-requests)
- [JavaScript Reference](/scripting/javascript-reference)
- [XML Post Examle](/scripting/xml-example)

## Testing

Expand Down