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

papi

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

papi - npm Package Compare versions

Comparing version 0.28.0 to 0.29.0

17

lib/constants.js

@@ -55,10 +55,19 @@ 'use strict';

'agent',
'pfx',
// tls
'ca',
'cert',
'ciphers',
'clientCertEngine',
'crl',
'dhparam',
'ecdhCurve',
'honorCipherOrder',
'key',
'passphrase',
'cert',
'ca',
'ciphers',
'pfx',
'rejectUnauthorized',
'secureOptions',
'secureProtocol',
'servername',
'sessionIdContext',
];

@@ -65,0 +74,0 @@

@@ -7,5 +7,2 @@ /**

var http = require('http');
var stream = require('stream');
/**

@@ -26,2 +23,12 @@ * Check if object is empty

/**
* Check stream
*/
function isStream(s) {
return s !== null &&
typeof s === 'object' &&
typeof s.pipe === 'function';
}
/**
* Check readable stream

@@ -31,3 +38,3 @@ */

function isReadableStream(s) {
return s instanceof stream.Readable;
return isStream(s) && s.readable !== false;
}

@@ -40,3 +47,3 @@

function isWritableStream(s) {
return s instanceof stream.Writable || s instanceof http.ServerResponse;
return isStream(s) && s.writable !== false;
}

@@ -43,0 +50,0 @@

{
"name": "papi",
"version": "0.28.0",
"version": "0.29.0",
"description": "Build HTTP API clients",

@@ -5,0 +5,0 @@ "main": "lib",

@@ -24,15 +24,20 @@ # Papi [![Build Status](https://travis-ci.org/silas/node-papi.png?branch=master)](https://travis-ci.org/silas/node-papi)

* baseUrl (String): base URL, should not include trailing slash
* headers (Object<String, String>, optional): defaults headers to include in every request
* type (String, optional, supports: form, json, text): default request body encoding type
* encoders (Object<String, Function>, optional): an object that maps a mime type to a function. The function should accept an object and return a Buffer.
* decoders (Object<String, Function>, optional): an object that maps a mime type to a function. The function should accept a Buffer or String (must support both) and return an object.
* tags (String[], optional): tags included in `_log` calls
* timeout (Number, optional): default number of milliseconds before request is aborted
* baseUrl (string): base URL, should not include trailing slash
* headers (Object<string, string>, optional): defaults headers to include in every request
* type (string, optional, supports: form, json, text): default request body encoding type
* encoders (Object<string, Function>, optional): an object that maps a mime type to a function. The function should accept an object and return a Buffer.
* decoders (Object<string, Function>, optional): an object that maps a mime type to a function. The function should accept a Buffer or string (must support both) and return an object.
* tags (string[], optional): tags included in `_log` calls
* timeout (number, optional): default number of milliseconds before request is aborted
Advanced options
* agent (http.Agent|https.Agent, optionals): if not set uses the global agent
* tls options: ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder, key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, and sessionIdContext (see [Node.js docs](https://nodejs.org/dist/latest/docs/api/tls.html#tls_tls_connect_options_callback) for details)
Usage
``` javascript
var papi = require('papi');
var util = require('util');
const papi = require('papi');
const util = require('util');

@@ -62,17 +67,17 @@ function GitHub(opts) {

* request (Object): request options
* callback... (Function<request, next>, optional): middleware functions that can mutate `request.err` or `request.res`. Call `next` without arguments to continue execution, `next(err)` to break with an error, or `next(false, arguments...)` to trigger the final callback with the given arguments.
* callback (Function<err, res>): request callback function.
* callback... (Function<request, next>, optional): middleware functions that can mutate `request.err` or `request.res`. Call `next` without arguments to continue execution, `next(err)` to break with an error, or `next(false, arguments...)` to trigger the final callback with the given arguments
* callback (Function<err, res>): request callback function
Request
* path (String): request path, can include variable segments defined by curly braces (ex: `/user/{id}`)
* method (String): request method
* headers (Object<String, String>, optional): request headers
* params (Object<String, String>, optional): sets variables in request path
* query (Object<String, String|String[]>, optional): query parameters
* path (string): request path, can include variable segments defined by curly braces (ex: `/user/{id}`)
* method (string): request method
* headers (Object<string, string>, optional): request headers
* params (Object<string, string>, optional): sets variables in request path
* query (Object<string, string|string[]>, optional): query parameters
* body (Object|Buffer|Readable, optional): request body
* type (String, optional, supports: form, json, text): request body encoding type
* type (string, optional, supports: form, json, text): request body encoding type
* ctx (EventEmitter, optional): emit `cancel` to abort request
* timeout (Number, optional): number of milliseconds before request is aborted
* tags (String[], optional): tags included in `_log` calls
* timeout (number, optional): number of milliseconds before request is aborted
* tags (string[], optional): tags included in `_log` calls

@@ -86,3 +91,3 @@ There are also `_get`, `_head`, `_post`, `_put`, `_delete` (`_del`), `_patch`,

GitHub.prototype.gists = function(username, callback) {
var opts = {
const opts = {
path: '/users/{username}/gists',

@@ -92,3 +97,3 @@ params: { username: username },

this._get(opts, function(err, res) {
this._get(opts, (err, res) => {
if (err) return callback(err);

@@ -115,3 +120,3 @@

* tags (String[]): tags associated with event
* tags (string[]): tags associated with event
* data (optional): remaining arguments

@@ -144,3 +149,3 @@

* event (String): event name
* event (string): event name
* callback (Function): function to execute at a specified point during the request

@@ -151,3 +156,3 @@

``` javascript
client._ext('onRequest', function(request, next) {
client._ext('onRequest', (request, next) => {
console.log('request', request.opts.method + ' ' + request.opts.path);

@@ -160,5 +165,5 @@

client._ext('onResponse', function(request, next) {
var duration = new Date() - request.start;
var statusCode = request.res ? request.res.statusCode : 'none';
client._ext('onResponse', (request, next) => {
const duration = new Date() - request.start;
const statusCode = request.res ? request.res.statusCode : 'none';

@@ -203,3 +208,3 @@ console.log('response', request.opts.method, request.opts.path, statusCode, duration + 'ms');

* url (String): request url (ex: `http://example.org/`)
* url (string): request url (ex: `http://example.org/`)

@@ -212,5 +217,5 @@ There are also `get`, `head`, `post`, `put`, `delete` (`del`), `patch`, and

``` javascript
var papi = require('papi');
const papi = require('papi');
papi.get('https://api.github.com/users/silas/gists', function(err, res) {
papi.get('https://api.github.com/users/silas/gists', (err, res) => {
if (err) throw err;

@@ -232,4 +237,4 @@

var papi = require('papi');
var util = require('util');
const papi = require('papi');
const util = require('util');

@@ -278,3 +283,3 @@ /**

GitHub.prototype.gists = function(username, callback) {
var opts = {
const opts = {
path: '/users/{username}/gists',

@@ -292,5 +297,5 @@ params: { username: username },

function main() {
var github = new GitHub({ debug: true });
const github = new GitHub({ debug: true });
github.gists('silas', function(err, res) {
github.gists('silas', (err, res) => {
if (err) throw err;

@@ -297,0 +302,0 @@

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