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

@acheetahk/request

v2.10.4

Published

✨ work with request

Downloads

146

Readme

codecov build npm

Please use version greater than 2.9.0

Methods Nav

Installation

npm install @acheetahk/request

cnpm install @acheetahk/request

yarn add @acheetahk/request

Dependencies

{
    "@types/express": "^4.17.8",
    "@types/form-data": "^2.5.0",
    "axios": "^0.21.0",
    "form-data": "^3.0.0"
}

Usage

fastRequest

fastRequest - get

  import { fastRequest } from '@acheetahk/request';
  const response = await fastRequest({ url: <YOUR URL>, method: 'GET' });

fastRequest - post

  import { fastRequest } from '@acheetahk/request';
  const response = await fastRequest({ url: <YOUR URL>, method: 'POST', data: { value: 'test post' } });

fastRequest - options

|param|type|explain|require| |:-:|:-:|:-:|:-:| |url|string|url|true| |method|GET DELETE HEAD OPTIONS POST PUT PATCH PURGE LINK UNLINK|method|true| |headers|any|header|false| |query|any|Concatenate parameters in the URL|false| |data|any|data Apply only to these request methods 'PUT', 'POST', and 'PATCH'|false| |timeout|number|timeout Units are seconds|false| |withCredentials|boolean|allows cookie information to be carried across domains|false| |responseType|arraybuffer blob document json text stream|response-type|false| |onUploadProgress|(progressEvent: any) => void|Configure the progress on upload|false| |onDownloadProgress|(progressEvent: any) => void|Configure the progress on download|false| |proxy|{ host: string, port: number, auth: { username: string, password: string } }| Configure proxy |false| |decompress|boolean| indicates whether or not the response body should be decompressed |false|

fastFormData

fastFormData - example

  import * as fs from 'fs';
  import { fastFormData } from '@acheetahk/request';

  const response = await fastFormData(
    {
      url,
      data: {
        name: 'test formData',
        file: fs.createReadStream(resolve(__dirname, './xx.xx')),
      },
    },
  );

fastFormData - options

|param|type|explain|require| |:-:|:-:|:-:|:-:| |url|string|Resources to address|true| |data|any|form-data body|true| |configs|RequestOptions| ⬇️ 👀 |true|

fastFormData - options - configs

|param|type|explain|require| |:-:|:-:|:-:|:-:| |headers|any|header|false| |timeout|number|timeout Units are seconds|false| |withCredentials|boolean|allows cookie information to be carried across domains|false| |responseType|arraybuffer blob document json text stream|response-type|false| |onUploadProgress|(progressEvent: any) => void|Configure the progress on upload|false| |onDownloadProgress|(progressEvent: any) => void|Configure the progress on download|false| |decompress|boolean| indicates whether or not the response body should be decompressed |false|

fastProxy

Delegate to the specified express.js / nest.js service

fastProxy - example for nest.js

import { NestFactory } from '@nestjs/core';
import { Module, All, Controller, HttpCode, HttpStatus, InternalServerErrorException, Req } from '@nestjs/common';

@Controller('demo')
class DemoController {
  @All()
  @HttpCode(HttpStatus.OK)
  async demo(@Req() requset: Request) {
    try {
      await fastProxy(
        requset,
        requset.res,
        {
          host: '<The server host that requires a proxy>',
          port: '<The server port that requires a proxy>',
          isRewrite: true,
          rewrite: '/demo',
          body: requset.body,
          path: requset.originalUrl,
          headers: requset.headers,
        },
      );
    } catch (error) {
      throw new InternalServerErrorException('Error');
    }
  }
}

const app = await NestFactory.create(CoreModule, { cors: true });
await app.listen(8000);

fastProxy - example of express.js

import * as express from 'express';
import { fastProxy } from '@acheetahk/request';

const app = express();

const router = express.Router();

app.use('/express', router);

router.all('*', async (requset: Request, response: Response) => {
  await fastProxy(
    requset,
    response,
    {
      host: '<The server host that requires a proxy>',
      port: '<The server port that requires a proxy>',
      isRewrite: true,
      rewrite: '/express',
      body: requset.body,
      path: requset.originalUrl,
      headers: requset.headers,
    },
  );
});

const server = app.listen(8000);

fastProxy - options

|param|type|explain|require| |:-:|:-:|:-:|:-:| |req|express.request|The bottom layer is HTTP.IncomingMessage|true| |res|express.response|The bottom layer is HTTP.ServerResponse|true| |options|ProxyOptions| ⬇️ 👀 |true|

fastProxy - options - options

|param|type|explain|require| |:-:|:-:|:-:|:-:| |host| string |The server host that requires a proxy|true| |port| number |The server port that requires a proxy|true| |path|string|The routing address|true| |headers|any|The request header|true| |body| any |The request body|false| |timeout|number|timeout Units are seconds|false| |isRewrite|boolean|Whether to override the routing address|false| |rewrite|string|example of rewrite rule: '/express' ==> '/' or '/express/test' ==> '/test'|false|

fileDownload

fileDownload - example

Download the file and return to the local file path

import { resolve } from 'path';

const path = resolve(__dirname, './fileDownload');
const url = <YOUR FILE URL>;

// result -> The full path of the downloaded file
const result = await fileDownload(url, path);

fileDownload - args

|param|type|require| |:-:|:-:|:-:| |url|string|true| |path|string|true|

fileToStr

fileToStr - example

Convert the network file into a string of the specified encoding

const url = <YOUR FILE URL>;
const result = await fileToStr(url);

fileToStr - args

|param|type|explain|require| |:-:|:-:|:-:|:-:| |url|string|url|true| |type|string|Encoding type, the default is base64|true|

fileToBuffer

fileToBuffer - example

Convert web files to Buffer

const url = <YOUR FILE URL>;
const result = await fileToBuffer(url, path);

fileToBuffer - args

|param|type|require| |:-:|:-:|:-:| |url|string|true|

fileToDuplexStream

fileToDuplexStream - example

Convert web files to Duplex Stream

const url = <YOUR FILE URL>;
const result = await fileToDuplexStream(url, path);

fileToDuplexStream - args

|param|type|require| |:-:|:-:|:-:| |url|string|true|

bufferToStream

bufferToStream - example

const result = await bufferToStream(buffer);

bufferToStream - args

|param|type|require| |:-:|:-:|:-:| |buffer|Buffer|true|


LICENSE