https://github.com/navneetlal/xml-middleware-expressjs
XML middleware to provide support for xml with easy setup
https://github.com/navneetlal/xml-middleware-expressjs
Last synced: 9 days ago
JSON representation
XML middleware to provide support for xml with easy setup
- Host: GitHub
- URL: https://github.com/navneetlal/xml-middleware-expressjs
- Owner: navneetlal
- Created: 2021-04-12T12:11:03.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T00:14:18.000Z (about 2 years ago)
- Last Synced: 2025-04-19T01:08:40.630Z (about 1 month ago)
- Language: TypeScript
- Size: 136 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# XML Middleware
A simple middleware for expressjs which allow an easy setup for xml support. Apart from that it also provides a standard response object for consistency.
## Installing
Using npm:
```bash
npm install @navneetlal/xml-middleware --save
```Using yarn:
```bash
yarn add @navneetlal/xml-middleware
```## Usage
`body-parser` or other (which can parse request body to text) is required for this middleware to work.
### CommonJS usage
```js
const xmlMiddleware = require('@navneetlal/xml-middleware');
const { text as textParserMiddleware } = require('body-parser');app.use(textParserMiddleware({ type: ['xml', '+xml', 'text/xml'] }));
app.use(xmlMiddleware());
```Now in order to send response, use `res.sendResponse()` instead of standard method provided by express.
You can also make use of `ServerResponse` class to construct a response object
```js
const responseObject = new ServerResponse(true, 'Success')
responseObject.results = { some: 'json' }res.sendResponse(responseObject)
res.sendResponse(400, new ServerResponse(false, 'Oops! Somethings doesn\'t look right'))
```### Typescript usage
This package is built on typescript and provides full support for the same.
## Issues
In case of any problem in the package open an issue here at [https://github.com/navneetlal/xml-middleware-expressjs/issues](https://github.com/navneetlal/xml-middleware-expressjs/issues)