
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
fastify-xml-body-parser
Advanced tools
Fastify plugin / module to parse XML payload / body into JS object
$npm install fastify-xml-body-parser
#or
$yarn add fastify-xml-body-parser
Sample POST body / payload
<sample>data</sample>
const fastify = require('fastify')()
fastify.register(require('fastify-xml-body-parser'))
fastify.post('/', (req, reply) => {
console.log(req.body.sample)//data
reply.send(req.body)
})
fastify.listen(8000, (err) => {
if (err) throw err
})
The sent reply would be the object:
{
sample: 'data'
}
This plugin use fast-xml-parser to parse the XML payload. So it accepts all the options supported by fast-xml-parser.
var options = {
attributeNamePrefix : "@_",
attrNodeName: "attr", //default is 'false'
textNodeName : "#text",
ignoreAttributes : true,
ignoreNameSpace : false,
allowBooleanAttributes : false,
parseNodeValue : true,
parseAttributeValue : false,
trimValues: true,
decodeHTMLchar: false,
cdataTagName: "__cdata", //default is 'false'
cdataPositionChar: "\\c",
};
const fastify = require('fastify')()
fastify.register(require('fastify-xml-body-parser'), options)
Additionaly, it supports following options
true
, this plugin validate the payload for valid XML syntax before parsing.["text/xml", "application/xml", "application/rss+xml"]
.Note: I've not included body size limit to this plugin because of following reasons
Don't forget to check my other opensource projects
FAQs
Fastify plugin to parse XML payload into JS object
The npm package fastify-xml-body-parser receives a total of 7,353 weekly downloads. As such, fastify-xml-body-parser popularity was classified as popular.
We found that fastify-xml-body-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.