0.6.4 • Published 8 years ago

restful-qs v0.6.4

Weekly downloads
13
License
ISC
Repository
github
Last release
8 years ago

RESTful Query String Parser Build Status npm version

Parse querystrings into queries for your RESTful services.

Install

$ npm i restful-qs

Usage

String parsing:

'use strict';
var parseRESTfulQuery = require('./');

var qs = 'age=29&name=Sabrina&link=friends&embed=hobbies,adventures';
var parsed = parseRESTfulQuery(qs);

console.log(JSON.stringify(parsed, null, 2));

Inside a web server:

'use strict';
var url = require('url');
var http = require('http');

var parseRESTfulQuery = require('../');

http.createServer(function (request, response) {
  var query = url.parse(request.url).query || 'sort=foo';
  var restfulQuery = parseRESTfulQuery(query);
  var out = JSON.stringify(restfulQuery, null, 2);

  response.writeHead(200, {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(out),
  });
  response.end(out);
})
.listen(3000);

console.log('listening at http://localhost:3000/');

API

parseRESTfulQuery(qs)

Parses a string or object into a RESTful query.

0.6.4

8 years ago

0.6.3

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.5.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago