JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 75943
  • Score
    100M100P100Q138008F
  • License Apache-2.0

Sugar API for @request/core consumers

Package Exports

  • @request/api

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@request/api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@request/api

npm-version travis-ci coveralls-status

var api = require('@request/api')
var client = require('@request/client')

// API methods configuration
var config = {
  // HTTP methods
  method: {
    get: ['select']
  },
  // @request/core option methods
  option: {
    qs: ['where']
  },
  // custom methods
  custom: {
    request: ['fetch', 'snatch', 'submit']
  }
}

// custom methods implementation
var custom = {
  // pass any arguments to your custom methods
  request: function (callback) {
    if (callback) {
      // `this._options` contains the generated options object
      this._options.callback = callback
    }
    // the last method should return @request/core consumer
    return client(this._options)
    // return `this` if you want to chain further
  }
}

// initialize the API
var request = api(config, custom)

// GET http://localhost:6767?a=1
request
  .select('http://localhost:6767')
  .where({a: 1})
  .fetch((err, res, body) => {
    // request callback
  })

See @request/core for more details.