🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

restify-json-filtering

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify-json-filtering

A formatter to filter json object with a fields param

1.0.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

restify-json-filtering

Visit http://anyfetch.com for details about AnyFetch.

This is a custom restify formatter to filter properties on JSON objects according to some custom param fields

How does this work?

Let's say you have an endpoint /search returning the following data:

{
  "count": 2,
  "next_page": "http://example.org/page3",
  "prev_path": "http://example.org/page1",
  "facets": {
    "owners": {
      "user": 0,
      "admin": 2
    },
    "creators": {
      "user": 1,
      "admin": 2
    }
  },
  "documents": [
    {
      "id": 1,
      "name": "My document",
      "snippet": "Some textual content"
    },
    {
      "id": 2,
      "name": "My other document",
      "snippet": "Some textual content"
    }
  ]
}

Once you setup this lib, when loading /search?fields=count,documents.id you'll see:

{
  "count": 2,
  "documents": [
    {
      "id": 1
    },
    {
      "id": 2
    }
  ]
}

Syntax

This should be a comma separated list of fields you want to retrieve. Arrays are "ignored" (see example above).

Leaving the parameter empty will not do any filtering. Adding a trailing . (dot) can be used to remove the content of an object (to count the number of items in an array without loading all the data).

How to use

var restify = require('restify');
// Replace "fields" by any name -- this will be used for the filtering data.
var restifyJsonFilterer = require('restify-json-filtering')('fields');

var server = restify.createServer({
  formatters: {
    'application/json': restifyJsonFilterer
  }
});

// You need to add *at least* this middleware
server.use(restify.queryParser());

Support: support@anyfetch.com.

Keywords

restify

FAQs

Package last updated on 08 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts