Yes, simply use the project as a module and modify router.render to output XML. If you look for "json to xml" on npm, you can find some libraries to help you convert data to XML.
You may need to test if data is an array though and put it into an object, since most converter requires objects to be passed.
var jsonServer = require('json-server')
var server = jsonServer.create()
var router = jsonServer.router('db.json')
var middlewares = jsonServer.defaults()
server.use(middlewares)
server.use(router)
router.render = function (req, res) {
var data = res.locals.data
var str = convertDataToXML(data)
res.send(str)
}
server.listen(3000, function () {
console.log('JSON Server is running')
})
PS: sorry for not suggesting a particular XML converter, it's just that I haven't tried them.
Where is the code for "convertDataToXML"?
If I post an xml data, how to change the code?
Most helpful comment
Yes, simply use the project as a module and modify
router.renderto output XML. If you look for "json to xml" on npm, you can find some libraries to help you convert data to XML.You may need to test if data is an array though and put it into an object, since most converter requires objects to be passed.
PS: sorry for not suggesting a particular XML converter, it's just that I haven't tried them.