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 - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

26

index.js
module.exports = (config, submit) => {
module.exports = (config, custom) => {

@@ -7,3 +7,3 @@ return ((options) => {

function wrapVerb (key) {
function wrapMethod (key) {
return (url) => {

@@ -16,7 +16,7 @@ options.method = key.toUpperCase()

Object.keys(config.verb).forEach((key) => {
api[key] = wrapVerb(key)
Object.keys(config.method || {}).forEach((key) => {
api[key] = wrapMethod(key)
config.verb[key].forEach((alias) => {
api[alias] = wrapVerb(key)
config.method[key].forEach((alias) => {
api[alias] = wrapMethod(key)
})

@@ -32,3 +32,3 @@ })

Object.keys(config.option).forEach((key) => {
Object.keys(config.option || {}).forEach((key) => {
api[key] = wrapOption(key)

@@ -41,6 +41,12 @@

api.submit = submit.bind(options)
function wrapCustom (key) {
return custom[key].bind(api, options)
}
config.custom.submit.forEach((alias) => {
api[alias] = submit.bind(options)
Object.keys(config.custom || {}).forEach((key) => {
api[key] = wrapCustom(key)
config.custom[key].forEach((alias) => {
api[alias] = wrapCustom(key)
})
})

@@ -47,0 +53,0 @@

{
"name": "@request/api",
"version": "0.1.0",
"version": "0.2.0",
"description": "Sugar API for @request/core consumers",

@@ -5,0 +5,0 @@ "keywords": [

@@ -12,8 +12,9 @@

// all API methods and their aliases
var config = {
// HTTP verb methods
verb: {
// HTTP methods
method: {
get: ['select']
},
// option methods
// @request/core option methods
option: {

@@ -25,2 +26,3 @@ qs: ['where'],

custom: {
check: [],
submit: ['gimme']

@@ -30,16 +32,28 @@ }

function submit () {
// `this` contains the options object that you usually pass to @request/core
return client(this)
// 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, submit)
var request = api(config, custom)
// GET http://localhost:6767?a=b
request
.select('http://localhost:6767')
.select('http://localhost')
.check('localhost')
.where({a: 'b'})
.done((err, res, body) => {
// aaa
// mazing
// request callback
})

@@ -46,0 +60,0 @@ .gimme()

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