Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@request/api

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@request/api

Sugar API for @request/core consumers

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51K
increased by11.68%
Maintainers
2
Weekly downloads
 
Created
Source

@request/api

npm-version travis-ci coveralls-status

Use this module to create sugar API for your HTTP client. You can also allow your users to define their own method aliases.

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

// all API methods and their aliases
var config = {
  // HTTP methods
  method: {
    get: ['select']
  },
  // @request/core option methods
  option: {
    qs: ['where'],
    callback: ['done']
  },
  // custom methods
  custom: {
    check: [],
    submit: ['gimme']
  }
}

// custom method implementation
var custom = {
  // `host` is parameter passed to your method
  check: function (options, host) {
    if (/localhost/.test(host)) {
      options.url += ':6767'
    }
    // `this` contains the API itself, for chaining purposes
    return this
  },
  // `options` contains the generated options object from the preceding methods
  submit: function (options) {
    // the last method should return a @request/core consumer
    return client(options)
  }
}

var request = api(config, custom)

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

See @request/core for more details.

Keywords

FAQs

Package last updated on 08 Feb 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc