mof-json
v1.0.3
Published
A middleware wrapper of JSON parsing for floodesh
Downloads
23
Maintainers
Readme
mof-json
mof-json is a middleware of floodesh, it automatically parses response to JSON as long as one of below conditions is met:
- Content-Type is kind of 'json'
- Current url matches the provided RegExp
p
Install
npm install mof-json
Usage
const json = require('mof-json');
const request = require('mof-request');
const Worker = require("floodesh/worker");
const worker = new Worker();
worker.use(co.wrap(request(worker.config.downloader))); // make sure the ctx existing before using json
// default parse only Content-Type is json
worker.use(json());
// parse when Content-Type is json or url matches pattern
const options = {p: /\/path\/to\/page/};
worker.use(json(options));
Test
npm test