UNPKG

ninjs-request

Version:
48 lines (37 loc) 1.07 kB
'use strict' const _ = require('ninjs-lodash') const request = require('../') const fs = require('fs-extra') const http = require('http') const _NAME = _.path.name(__filename) const _NS = `ninjs.request.test.${_NAME}` const _URL = 'https://google.com' module.exports = { NAME: _NAME, NS: _NS, DIR: __dirname, FILE: __filename, run: run, get: get } function run(options) { toFile() toPut() toPost() getPut() getPost() getPutWithResponseEvent() getPutWithErrorEvent() httpTest() advancedHttpTest() piping() } // You can stream any response to a file stream. function toFile() { request('http://google.com/doodle.png') .pipe(fs.createWriteStream('doodle.png')) } request supports making requests to UNIX Domain Sockets. To make one, use the following URL scheme: /* Pattern */ 'http://unix:SOCKET:PATH' /* Example */ request.get('http://unix:/absolute/path/to/unix.socket:/request/path') Note: The SOCKET path is assumed to be absolute to the root of the host file system.