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

simply-https

v2.0.0

Published

A light weight yet an efficient https module to make api requests

Downloads

11

Readme

⚡ simply-https

A light weight yet an efficient HTTPS module to make API requests

[!IMPORTANT] Welcome to v2.0.0

What's new?

  • New syntax to make it easy to switch from node-fetch or vanilla fetch() to simply-https
  • Faster, Efficient, More Type strict.
  • Supports various types for response
  • Fully supports all HTTPS methods
  • Less bloat.

Functions

https()

Https function to replace your good ol' node-fetch and axios.

const { https } = require("simply-https");
https("url", {
  // options (optional)
});

This returns a Promise so you should await it and should be located inside an async function. Or your project should be configured to top-level await

Types:

https(
  url: string,
  options?: HttpsOptions
): Promise<object | Buffer | string | Resolver | ArrayBuffer | Blob>;
  • url: string

  • options: HttpsOptions

  • Resolves: Promise<object | Buffer | string | Resolver | ArrayBuffer | Blob>

Options

HttpsOptions

| Parameters | Type | Default | Description | | -------------- | ---------------------------------------------------------------------------------------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | body | object | string (passed as JSON.stringify()) | | The body to send the request (cannot be used in 'GET' request) | | url | string | | The URL to call the API (if you are not using the second argument and not using hostname and endpoint options) | | hostname | string | | The hostname of the url (Not necessary if URL argument has endpoint with it) | | endpoint | string | | Endpoint to request to (Not necessary if URL argument has endpoint with it) | | headers | Record<string, string> | { "Content-Type": "application/json" } | The headers of the request | | method | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "CONNECT" | "OPTIONS" | "TRACE" | GET | The method of request to do with the URL | | responseType | "json" | "stream" | "text" | "blob" | "arrayBuffer" | "buffer" | | Returns Resolver class where you can do .toJSON, .toString, .toBuffer, .toStream, .toBlob or Promised functions like .json(), .stream(), .text(), .blob() to support vanilla fetch syntax | | statusCode | number | 200 | Expected status code | | timeout | number | 5000 | The time limit untill it gets HTTP Timeout |

interface HttpsOptions {
  body?: object | string;
  url?: string;
  hostname?: string;
  endpoint?: string;
  headers?: Record<string, string>;
  method?:
    | "GET"
    | "POST"
    | "PUT"
    | "PATCH"
    | "DELETE"
    | "HEAD"
    | "CONNECT"
    | "OPTIONS"
    | "TRACE";
  responseType?: "json" | "stream" | "text" | "blob" | "arrayBuffer" | "buffer";
  statusCode?: number;
  timeout?: number;
}

Response

It returns a Resolver class which contains

Promise based functions

  • arrayBuffer() | array()
  • blob()
  • buffer() | stream()
  • json()
  • text() | string()

Not Promise based

  • toArrayBuffer()
  • toBlob()
  • toBuffer() | toStream()
  • toJSON()
  • toText() | toString()

These functions are used to resolve your data stream into desired format. Can convert into ArrayBuffer Blob Buffer JSON String

Examples

With await

const { https } = require("simply-https");

// should be inside a async function or have top-level await
const data = await https("postman-echo.com/get");
const res = await res.json();
console.log(res);

With .then()

const { https } = require("simply-https");

https("postman-echo.com/get")
  .then((data) => data.json())
  .then((res) => console.log(res));
const { https } = require("simply-https");

https("https://httpbin.org/post", {
  method: "POST",
})
  .then((data) => data.json())
  .then((res) => console.log(res));

With post body

const { https } = require("simply-https");

https("https://httpbin.org/post", {
  method: "POST",
  body: { message: "hello world" },
})
  .then((data) => data.json())
  .then((res) => console.log(res));
const { fetch } = require("node-fetch");

fetch("https://httpbin.org/post", {
  method: "POST",
})
  .then((data) => data.json())
  .then((res) => console.log(res));
const { https } = require("simply-https");

https("https://httpbin.org/post", {
  method: "POST",
  body: { message: "hello world" },
})
  .then((data) => data.json())
  .then((res) => console.log(res));
- fetch("https://httpbin.org/post", {
+ https("https://httpbin.org/post", {

Its that simple. No bloat, no sloppy anymore.