New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
decreased by-13.38%
Maintainers
2
Weekly downloads
 
Created
Source

@request/api

npm-version travis-ci coveralls-status

Basic API

request('url')
request({options})
request('url', function callback (err, res, body) {})
request({options}, function callback (err, res, body) {})
request('url', {options}, function callback (err, res, body) {})

request[HTTP_VERB]('url')
request[HTTP_VERB]({options})
request[HTTP_VERB]('url', function callback (err, res, body) {})
request[HTTP_VERB]({options}, function callback (err, res, body) {})
request[HTTP_VERB]('url', {options}, function callback (err, res, body) {})
var api = require('@request/api')
var client = require('@request/client')

// initialize the API
var request = api({
  type: 'basic',
  // pass HTTP request function
  // that accepts @request/interface options
  request: client
})

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

Chain API

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

// initialize the API
var request = api({
  type: 'chain',
  // API methods configuration
  config: {
    // HTTP methods
    method: {
      get: ['select'],
      // ...
    },
    // @request/interface option methods
    option: {
      qs: ['where'],
      // ...
    },
    // custom methods
    custom: {
      request: ['fetch', 'snatch', 'submit'],
      // ...
    }
  },
  // custom methods implementation
  define: {
    // 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/interface consumer
      return client(this._options)
      // or
      return this // if you want to chain further
    }
  }
})

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

Keywords

FAQs

Package last updated on 02 May 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