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

asynquence-request

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asynquence-request

Provides 'request' as plugin for asynquence.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

asynquence-request Build Status

This is a Node.js wrapper / plugin that makes using request easier with the asynquence library. If you haven't heard of the asynquence library, you should check it out. It's like Promises on steroids.

NPM

Example usage

In order to avoid depending on any specific versions of request or asyncquence, this module does not directly depend on them. (To be technical, they are peerDependencies.) You require them yourself and pass them into the module function like so:

ASQ = require 'asynquence'
request = require 'request'
require('asynquence-request')(ASQ, request)

This extends ASQ with the following plugins which directly correspond to their request counterpart: get, head, post, put, patch, del. Here's a fictional example usage of a REST API:

ASQ = require 'asynquence'
request = require 'request'

# We can pass in a modified version of 'request' such as the kind returned by 'request.defaults'
req = request.defaults
  baseUrl: 'http://petstore.swagger.io/v2/'
  json: true
  headers: 'Authorization': 'Bearer special-key'

require('asynquence-request')(ASQ, req)

ASQ()
# You can either pass in a request options literal...
.post
  url: 'pet'
  json: 
    id: 42
    name: "doggie"
.val (response, body) ->
  console.log "Created pet with id: #{body.id}"
  return body.id
# Or you can pass in a function that will return a request options literal.
.del (id) -> "pet/#{id}"
# Every request returns two parameters: response and body
.then (done, response, body) ->
  console.log "HTTP Status: #{response.statusCode}"
  setTimeout done, 1000
.get "pet/42"
# HTTP Errors (status codes >= 400) conveniently throw an error for you
.or (err) ->
  if err.name is "404 Error"
    console.log "Who deleted Fido?!?!"
    console.log err.stack

TODO

  • cookie jar
  • more unit tests

Keywords

FAQs

Package last updated on 19 Sep 2015

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