gr-query-parse
v0.0.2
Published
Realiza o parse e stringify da query nas requisições e respostas.
Downloads
3
Maintainers
Readme
gr-query-parse
Realiza o parse e stringify da query nas requisições e respostas.
Realiza o encodeURI e decodeURI.
####Instalação
npm install gr-query-parse
####Teste (Stringify)
const gr = require('gr-query-parse')
let ob = {
order: 'desc',
vehicle: { factory: 'Hyundai', model: 'hb20' },
attributes: ['locale', 'color', 'price']
}
console.log( gr.stringify(ob) )
// order=desc&vehicle[factory]=Hyundai&vehicle[model]=hb20&attributes[]=locale&attributes[]=color&attributes[]=price
####Teste (Parse)
const gr = require('gr-query-parse')
// Request:
'localhost:8080/search?order=desc&vehicle[factory]=Hyundai&vehicle[model]=hb20&attributes[]=locale&attributes[]=color&attributes[]=price'
// Node.js:
app.get('/search', (req, res) => {
console.log(req.query)
res.sendStatus(202)
})
// console.log( gr.parse(url) )
{
order: 'desc',
vehicle: { factory: 'Hyundai', model: 'hb20' },
attributes: ['locale', 'color', 'price']
}