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

cuddle

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cuddle

Cuddle ===

  • 0.0.23
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
119
increased by36.78%
Maintainers
1
Weekly downloads
 
Created
Source

Cuddle

A very simple HTTP client for Node.js

npm install cuddle

Sample

var request = require('cuddle');

request.get
      .to('www.restserver.com', 3000, '/user/1')
      .then(callback);

Features

  1. Chainable
  2. Very readable
  3. Helps closures by using .args()
  4. Auto-retry for errors like ECONNREFUSED, ENOTFOUND, ECONNRESET, EADDRINFO, EMFILE

Functions

Function/PropertyParameterReturnDescription
cuddle(logger)logger e.g. console, winstoncuddleSets the logger
cuddle.stringify(object)objectstringConverts {a:1, b:2} to a=1&b=2
cuddle.getn/arequest objectInstantiates a GET request
cuddle.postn/arequest objectInstantiates a POST request
cuddle.putn/arequest objectInstantiates a PUT request
cuddle.deleten/arequest objectInstantiates a DELETE request
cuddle.request('PATCH')methodrequest objectInstantiates a request using the given method
request.to('host', port, 'path')host
port
path
itselfSets the request uri
request.add_header('header', 'value')header
value
itselfadds header
request.args('arg1', [arg2], {arg3}, arg4)any number of argumentsitselfAccepts any number of arguments and will be passed as the fourth paramater on callback as an [array]
request.set_before_json(fn)functionitselfAccepts a function to execute before parsing the data to JSON
request.raw()noneitselfDisable automatic JSON parsing, removes default application/json on Accept header
request.secured()noneitselfWill use https, but be sure to pass 443 as the port
request.send({data})dataitselfSets the payload
request.set_max_retry(5)numberitselfSets the max retry, default is 3
request.retry()noneitselfRetries the request
request.then(fn)functionitselfSets the callback then executes request. Callback arguments are err non-200 status codes will be considered as an error, result response data, request the request it self so you can call retry if you want and the request will have a response_headers property if you need it, lastly args if you used .args

Keywords

FAQs

Package last updated on 14 Nov 2014

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