npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aif-request

v0.0.3

Published

Simple methods to make data requests to a web server using the POST, GET methods, and the data encryption with AES algorithm.

Downloads

5

Readme

aif-request

Methods to make data requests to a web servers.

Simple methods to make data requests to a web server using the POST, GET methods, and the data encryption with AES algorithm is implemented for both the sending and the arrival of the data.

Installation

Download the library with npm / Yarn, from your local files.

Via NPM:

$ npm install aif-request

Via YARN:

$ yarn add aif-request

Use

The library can be included in your code through imports from CommonJS or ES.

ES2015 (ES6):

import online from "aif-request";

CommonJS:

var online = require("aif-request");

With ES imports it is also possible to use individual components. For example:

import { post, get } from "aif-request";

Methods

  • get (url, callback)
    Returns in function the callback the content of the body of the page given the url

  • post (url, data, callback)
    *Sends data that can contain data and files to the url and returns the content of the page body in response to the callback function.

  • download (url, dst, callback)
    It downloads a file from the url and stores it in the path dst, in case of success it returns true in the callback function.

For example:

const rq = require("aif-request");
const fs = require('fs');
const url = 'http://localhost/test'

rq.get(url + '/index.php', function(rs, err) {
  console.log('---------------------------------')
  console.log('method get', rs, err && err.toString())
})

rq.post(url + '/post.php', { 
  id: 'X9918',
  'file': fs.createReadStream('data/photo.jpg')
  }, function(rs, err) {
    console.log('------------------------------')
    console.log('method post', rs, err && err.toString())
})

rq.download(url + '/file.zip', './data', function(rs, err) {
  console.log('------------------------------')
  console.log('method dowmload', rs, err && err.toString())
})

Receive json data

  • getJson (url, callback)
    Returns in the ** callback ** function a JSON of the response from the url

  • postJson (url, data, callback)
    Sends the data that can contain data and files to the ** url ** and returns a JSON in the callback function as a response.

For example:

const rq = require("aif-request");
const url = 'http://localhost/test'

rq.getJson(url + '/data.json', function(rs, err) {
  console.log('---------------------------------')
  console.log('method get json', rs, err && err.toString())
})

rq.postJson(url + '/post-json.php', { id: 'X9918' }, function(rs, err) {
  console.log('------------------------------')
  console.log('method post json', rs, err && err.toString())
})

Use of data encryption

  • getCrypt (url, secret, [token], callback)
    Returns in the callback function a response from the url, only that before sending and receiving the data they are encrypted with a secret and token key, the latter is optional and must be 32 characters, if not defined one is generated and attached to the content that is sent.

  • postCrypt (url, data, secret, [token], callback)
    Sends the data that can contain data and files to the url, only that before sending and receiving the data they are encrypted with a secret and token key, The latter is optional and must be 32 characters, if not defined, one is generated and attached to the content that is sent, and only the fields will be encrypted, the files that are added will be sent without encryption.

Note. Encryption is completely transparent to the user, only the data will have to be decrypted on the server.

For example:

const rq = require("aif-request");
const url = 'http://localhost/test'

rq.getCrypt(url + '/crypt.json', '-secret-', function(rs, err) {
  console.log('---------------------------------')
  console.log('method get crypt', rs, err && err.toString())
})

rq.postCrypt(url + '/post-crypt.php', { id: 'X9918' }, '-secret-', function(rs, err) {
  console.log('------------------------------')
  console.log('method post crypt', rs, err && err.toString())
})

For example in POST sending to a server with PHP:

<?php
$data = $_POST['id'];
$key = '-secret-';
$token = substr($data, 0, 32);
$data = substr($data, 32);
$iv = substr($token,0,16);
$key = md5($key.$token);
$id = openssl_decrypt(base64_decode($data), 'aes-256-cbc', $key, true, $iv);
})

as a response in encrypted form in PHP

<?php
$data = 'Hello word';
$key = '-secret-';
$token = md5($key.uniqid(microtime()));
$iv = substr($token,0,16);
$key = md5($key.$token);
$res = $token.base64_encode(openssl_encrypt($data, 'aes-256-cbc', $key, true, $iv));
die($res);

In both cases the token is generated, but you could also use an authentication token and handle a secure channel for the duration of the session.

use of data encryption and json

  • getCryptJson (url, secret, [token], callback)

  • postCryptJson(url, data, secret, [token], callback)

similar to the previous ones but with a json response.

Note. For all these methods in case of error, returns the Error object as the second parameter.

Tests

$ npm test

O well

$ yarn test

build

$ npm run build

O well

$ yarn build

Security contact information

To report security vulnerabilities, use the following link: https://github.com/mygnet/aif-request/issues