Socket
Socket
Sign inDemoInstall

callarest

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callarest - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

.eslintrc.json

31

index.js

@@ -1,6 +0,7 @@

const http = require('http');
const https = require('https');
const ErrorWithObject = require('error-with-object');
import http from 'http';
import https from 'https';
function callarest (options, callback) {
export * as callarestJson from './json.js';
export function callarest (options, callback) {
const uri = new URL(options.url);

@@ -11,6 +12,7 @@

if (typeof options.body !== 'string') {
return callback(new ErrorWithObject({
message: 'You did not set the body property to an String. Did you mean to JSON.stringify an object it or use the callarest.json shortcut?',
code: 'SENT_OBJECT_AS_BODY'
}));
return callback(Object.assign(
new Error('callarest: You did not set the body property to an String. Did you mean to JSON.stringify an object it or use the callarest.json shortcut?'),
{
code: 'SENT_OBJECT_AS_BODY'
}));
}

@@ -46,7 +48,8 @@ headers['Content-Length'] = Buffer.byteLength(options.body);

request.on('error', (error) => {
callback(new ErrorWithObject({
code: 'REQUEST_ERROR',
...error,
request
}));
callback(Object.assign(
new Error('callarest: request error'), {
code: 'REQUEST_ERROR',
...error,
request
}));
});

@@ -60,2 +63,2 @@

module.exports = callarest;
export default callarest;

@@ -1,3 +0,2 @@

const ErrorWithObject = require('error-with-object');
const callarest = require('./');
import callarest from './index.js';

@@ -27,7 +26,9 @@ function callarestJson (options, callback) {

} catch (error) {
return callback(new ErrorWithObject({
code: 'RESPONSE_NOT_VALID_JSON',
message: 'The response body could not be JSON.parsed',
...rest
}));
return callback(Object.assign(
new Error('The response body could not be JSON.parsed'),
{
code: 'RESPONSE_NOT_VALID_JSON',
...rest
}
));
}

@@ -39,2 +40,2 @@

module.exports = callarestJson;
export default callarestJson;
{
"name": "callarest",
"version": "2.0.2",
"version": "3.0.0",
"type": "module",
"keywords": [

@@ -15,3 +16,4 @@ "rest",

"scripts": {
"test": "c8 -o /tmp node test"
"test": "c8 -o /tmp node test",
"lint": "eslint ."
},

@@ -22,4 +24,4 @@ "repository": {

},
"author": "",
"license": "ISC",
"author": "Mark Wylde <me@markwylde.com> (https://github.com/markwylde)",
"license": "MIT",
"bugs": {

@@ -30,9 +32,10 @@ "url": "https://github.com/markwylde/callarest/issues"

"devDependencies": {
"basictap": "^4.0.2",
"c8": "^7.2.1",
"righto": "^6.1.3",
"tape": "^5.0.1"
"righto": "^6.1.3"
},
"dependencies": {
"error-with-object": "^1.1.0"
"eslint": "^8.33.0",
"eslint-config-standard": "^17.0.0"
}
}
# Callarest
[![Build Status](https://travis-ci.org/markwylde/callarest.svg?branch=master)](https://travis-ci.org/markwylde/callarest)
[![David DM](https://david-dm.org/markwylde/callarest.svg)](https://david-dm.org/markwylde/callarest)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/markwylde/callarest)
[![GitHub package.json version](https://img.shields.io/github/package-json/v/markwylde/callarest)](https://github.com/markwylde/callarest/releases)
[![GitHub](https://img.shields.io/github/license/markwylde/callarest)](https://github.com/markwylde/callarest/blob/master/LICENSE)
A simple tool to natively make http(s) requests in node

@@ -13,3 +7,4 @@

```javascript
const callarest = require('callarest')
import { callarest } from 'callarest';
callarest({

@@ -29,3 +24,3 @@ method: 'post',

console.log('The body was:', rest.body);
// body will be a string

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

```javascript
const callarestJson = require('callarest/json)
import { callarestJson } from 'callarest';
callarestJson({

@@ -50,3 +46,3 @@ method: 'post',

console.log('The body was:', rest.body);
// body will be a javascript Object

@@ -53,0 +49,0 @@ })

@@ -1,3 +0,1 @@

const ErrorWithObject = require('error-with-object');
function parseBody (request, callback) {

@@ -18,3 +16,12 @@ let body = [];

} catch (error) {
return callback(new ErrorWithObject({ code: 400, error, body }));
const newError = Object.assign(
new Error('callarest: could not parseBody'),
{
code: 400,
error,
body
}
);
callback(newError);
return;
}

@@ -30,2 +37,2 @@ }

module.exports = parseBody;
export default parseBody;

@@ -1,6 +0,6 @@

const http = require('http');
const parseBody = require('./parseBody');
import http from 'http';
import parseBody from './parseBody.js';
let server;
function createServer (callback) {
export function createServer (callback) {
server = http.createServer((request, response) => {

@@ -27,3 +27,3 @@ if (request.url === '/echo' && request.method === 'POST') {

function createJsonServer (data, callback) {
export function createJsonServer (data, callback) {
if (arguments.length === 1) {

@@ -42,6 +42,8 @@ callback = data;

});
const dataToSend = data != null ? data : JSON.stringify({
a: 'you said',
b: body
});
const dataToSend = data != null
? data
: JSON.stringify({
a: 'you said',
b: body
});
response.end(dataToSend);

@@ -60,10 +62,4 @@ });

function destroyServer () {
export function destroyServer () {
server.close();
}
module.exports = {
createServer,
createJsonServer,
destroyServer
};

@@ -1,2 +0,2 @@

require('./raw');
require('./json');
import './raw.js';
import './json.js';

@@ -1,6 +0,6 @@

const test = require('tape');
const righto = require('righto');
import test from 'basictap';
import righto from 'righto';
const { createJsonServer, destroyServer } = require('./helpers/server');
const callarestJson = require('../json');
import { createJsonServer, destroyServer } from './helpers/server.js';
import callarestJson from '../json.js';

@@ -50,3 +50,3 @@ test('get -> success', t => {

request(function (error, result) {
t.equal(error.code, 'ENOTFOUND');
t.equal(error.code, 'EAI_AGAIN');
t.ok(error.request);

@@ -88,3 +88,6 @@ t.notOk(result);

t.ok(result);
t.deepEqual(result.body, { a: 'you said', b: '{"b":1}' });
t.deepEqual(result.body, {
a: 'you said',
b: '{"b":1}'
});

@@ -107,3 +110,6 @@ destroyServer();

if (error) { console.log(error); }
t.deepEqual(result.body, { a: 'you said', b: '"something"' });
t.deepEqual(result.body, {
a: 'you said',
b: '"something"'
});

@@ -110,0 +116,0 @@ destroyServer();

@@ -1,6 +0,6 @@

const test = require('tape');
const righto = require('righto');
import test from 'basictap';
import righto from 'righto';
const { createServer, destroyServer } = require('./helpers/server');
const callarest = require('../');
import { createServer, destroyServer } from './helpers/server.js';
import callarest from '../index.js';

@@ -14,3 +14,3 @@ test('get [https] -> success', t => {

request(function (error, result) {
request(function (error) {
t.equal(error.code, 'ECONNREFUSED');

@@ -46,3 +46,3 @@ });

request(function (error, result) {
t.equal(error.code, 'ENOTFOUND');
t.equal(error.code, 'EAI_AGAIN');
t.ok(error.request);

@@ -86,3 +86,3 @@ t.notOk(result);

request(function (error, result) {
request(function (error) {
t.equal(error.code, 'SENT_OBJECT_AS_BODY');

@@ -89,0 +89,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