GithubHelp home page GithubHelp logo

query-data's Introduction

query-data build status

Parse and serialize JSON data in a query parameter

Example

serialize and parse

const assert = require('assert')
const { serialize, parse } = require('query-data')

const query = serialize({ blam: 'pow' })
assert.equal(query, 'eyJibGFtIjoicG93In0=')

const data = parse(query)
assert.deepEqual(data, { blam: 'pow' })

Parse from a req object

const http = require('http')
const request = require('request')
const queryData = require('query-data')

const server = http.createServer((req, res) => {
  const data = queryData(req)
  res.end(JSON.stringify(data))
}).listen(1515)

const query = queryData.serialize({ blam: 'pow' })

request('http://localhost:1515?data=' + query, (err, res, body) => {
  console.log(body, query)
  server.close()
})

Usage

This module will parse and serialize between an object and a base64 encoded JSON string. { blam: 'pow' } becomes 'eyJibGFtIjoicG93In0=' and vice versa.

queryData(req, param='data')

The main export returns an object parsed from the request's querystring. param can be used to specify which parameter to parse. The value for this parameter should be a URI encoded, base64 encoding of a JSON string. Yeah, thats a mouthful.

queryData.serialize(obj)

Returns a base64 encoded JSON string of the provided object

queryData.parse(str)

Returns an object parsed from a base64 encoded JSON string

License

MIT

query-data's People

Contributors

timhudson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.