@luigisamurai/request-options
Help to configure the request parameters and to send HTTP request with the configured parameters.
Last updated a year ago by luigisamurai .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @luigisamurai/request-options 
SYNC missed versions from official npm registry.

REQUEST-PARAMETERS

Help to configure the request parameters and to send HTTP request with the configured parameters.

Pre requirements

  • NodeJs 6 or bigger

Install

npm install --save @luigisamurai/request-parameters

Use

const RequestParameters = require('@luigisamurai/request-parameters');

const request = new RequestParameters.Request();

// request-promises options
const setting = {
  resolveWithFullResponse: true,
  simple: false
};

// set the common parameters
request.setParameters({
  baseUrl: 'http://www.google.com',
  setting
});

// Get request with request-parameter dependency
const getPromise = request.send({
  method: 'get',
  urlParams: { homeId: 1 },
  queryParams: { offset: 0, limit: 100 },
  uri: '/home/{homeId}'
});

// Also can use async - await to wait the promises
getPromise.then((response) => {
  const statusCode = response.statusCode;
  const body = response.body;

  console.log(statusCode, ' ', body);
});

// Post request with request-parameter dependency
const postPromise = request.send({
  method: 'post',
  headers: { 'Content-Type': 'application/json' },
  uri: '/home',
  body: { name: 'home view' }
});

postPromise.then((response) => {
  const statusCode = response.statusCode;
  const body = response.body;

  console.log(statusCode, ' ', body);
});

// Note the URIs don't exist so the request return 404 status code.

Parameters configuration

You can specify the following parameters

  • baseUrl?: string
  • uri?: string
  • method?: string
  • headers?: any
  • urlParams?: any
  • queryParams?: any
  • body?: any
  • form?: any
  • formData?: any
  • setting?: Setting

Settings

  • resolveWithFullResponse?: boolean
  • simple?: boolean
  • transform?: () => any
  • agent?: boolean
  • port?: number
  • rejectUnauthorized?: boolean
  • requestCert?: boolean

References

Current Tags

  • 2.0.0-4                                ...           latest (a year ago)

3 Versions

  • 2.0.0-4                                ...           a year ago
  • 1.0.0-7                                ...           a year ago
  • 1.0.0-3                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (8)
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |