Skip to content

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

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

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
1 change: 1 addition & 0 deletions src/pages/testing/script/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default {
"request": "Request",
"response": "Response",
"dynamic-variables": "Dynamic Variables",
"xml-example": "XML Example",
}
33 changes: 33 additions & 0 deletions src/pages/testing/script/xml-example.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Callout } from "nextra/components";

# 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 copy filename="bruno.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:

```js copy
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()});
```