1.3.4 • Published 1 year ago

@kori_xyz/hermes v1.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

npm version Coverage Status install size npm downloads Known Vulnerabilities

Features

Install

Available for any computer running nodejs

yarn

yarn add @kori_xyz/hermes

npm

npm install @kori_xyz/hermes

Examples

this module is avaliable for CommonJS or ESM/Typescript

CommonJS

cookie session

const { Session } = require("@kori_xyz/hermes");

const client = new Session();

client
  .req({
    url: "https://discord.com",
  })
  .then((response) => {
    console.log(
      response,
      /**
       * cookies saved from previous request (automatic save)
       */
      client.cookies
    );
  });

using proxy

const Request = require("@kori_xyz/hermes");

Request({
  url: "https://api.ipify.org/?format=json",
  /**
   * automatic parse proxy (supporting auth config)
   */
  proxy: "47.254.153.200:80", // or "username:password@host:port"
  timeout: 10000,
}).then((response) => {
  /**
   * returns proxy ip
   */
  console.log(response.data);
});

downloading any media

const Request = require("@kori_xyz/hermes");
const { writeFileSync } = require("fs");

Request({
  url: "https://pt.wikipedia.org/static/images/mobile/copyright/wikipedia.png",
}).then((response) => {
  // learn about https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
  const mime_type = {
    media: response.headers["content-type"].split("/")[0],
    extension: response.headers["content-type"].split("/")[1],
  };

  const file_name = `./${mime_type.media}.${mime_type.extension}`;

  /**
   * saving media
   */
  writeFileSync(
    file_name,
    /**
     * `response.data` automatic transforms media in buffer
     */
    response.data,
    {
      flag: "w+",
    }
  );

  console.log(response.headers["content-type"], response.data.length);
});

ESM/TS

cookie session

import { Session } from "@kori_xyz/hermes";

const client = new Session();

const response = await client.req({
  url: "https://discord.com",
});

console.log(
  response,
  /**
   * cookies saved from previous request (automatic save)
   */
  client.cookies
);

using proxy

import Request from "@kori_xyz/hermes";

const response = await Request({
  url: "https://api.ipify.org/?format=json",
  /**
   * automatic parse proxy (supporting auth config)
   */
  proxy: "47.254.153.200:80", // or "username:password@host:port"
  timeout: 10000,
});

/**
 * returns proxy ip
 */
console.log(response.data);

downloading any media

import Request from "@kori_xyz/hermes";
import { writeFileSync } from "fs";

const response = await Request({
  url: "https://pt.wikipedia.org/static/images/mobile/copyright/wikipedia.png",
});

// learn about https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
const mime_type = {
  media: response.headers["content-type"].split("/")[0],
  extension: response.headers["content-type"].split("/")[1],
};
const file_name = `./${mime_type.media}.${mime_type.extension}`;

/**
 * saving media
 */
writeFileSync(
  file_name,
  /**
   * `response.data` automatic transforms media in buffer
   */
  response.data,
  {
    flag: "w+",
  }
);

console.log(response.headers["content-type"], response.data.length);

Request Config

{
  // `url` is the server URL that will be used for the request
  url: 'https://example.com/',

  // `method` is the request method to be used when making the request
  method: 'GET', // default

  // `headers` are custom headers to be sent
  headers: {'X-Requested-With': 'XMLHttpRequest'},

  // `payload` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH'
  // must be of one of the following types:
  // - string, plain object
  payload: {
    firstName: 'Fred'
  },

  // syntax alternative to send payload into the body
  payload: 'Country=Foo&City=Bar',

  // `timeout` specifies the number of milliseconds before the request times out.
  // If the request takes longer than `timeout`, the request will be aborted.
  timeout: 1000,

  // `proxy` defines the hostname, port, and protocol of the proxy server or string content  all.
  proxy: {
    protocol: 'https', // default
    host: '127.0.0.1',
    port: 80,
    username: 'foo',
    password: 'bar'
  },

   // support string, automatic parse
  proxy: 'https://foo:bar@127.0.0.1:80',

  // support http2
  http2: false // defaults
}

License

This project is licensed under the MIT - see the LICENSE file for details.

1.2.0

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.2.8

1 year ago

1.2.7

1 year ago

1.0.9

2 years ago

1.2.6

1 year ago

1.1.7

1 year ago

1.0.8

2 years ago

1.3.4

1 year ago

1.2.5

1 year ago

1.1.6

1 year ago

1.3.3

1 year ago

1.2.4

1 year ago

1.1.5

1 year ago

1.3.2

1 year ago

1.2.3

1 year ago

1.1.4

1 year ago

1.3.1

1 year ago

1.2.2

1 year ago

1.1.3

1 year ago

1.3.0

1 year ago

1.1.2

1 year ago

1.2.9

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.12

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago