From c22700542adb1ebf293900319991b76e6ced628a Mon Sep 17 00:00:00 2001 From: Tim Beermann Date: Thu, 23 Nov 2023 10:29:49 +0100 Subject: [PATCH] Add an example on how to post XML data that is pulled from an XMl file. Signed-off-by: Tim Beermann --- docs/scripting/xml-example.md | 31 +++++++++++++++++++++++++++++++ docs/table-of-contents.md | 1 + 2 files changed, 32 insertions(+) create mode 100644 docs/scripting/xml-example.md diff --git a/docs/scripting/xml-example.md b/docs/scripting/xml-example.md new file mode 100644 index 0000000..6625f94 --- /dev/null +++ b/docs/scripting/xml-example.md @@ -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()}); +``` diff --git a/docs/table-of-contents.md b/docs/table-of-contents.md index 3234581..4c1d366 100644 --- a/docs/table-of-contents.md +++ b/docs/table-of-contents.md @@ -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