Zaid-maker / simply-https

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

⚡ simply-https

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

Summary

https()

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

Implementation

const simply = require("simply-https");
simply.https("url", {
  method: "GET", // required
  // 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 | httpsOptions,
 options: httpsOptions = {
  method: 'GET',
  headers: { 'Content-Type': 'application/json' }
 }
): Promise<any>

get()

Just the https function but with "GET" method

Implementation

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

simply.get("url", {
  // options (optional)
});

post()

Just the https function but with "POST" method

Implementation

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

simply.post("url", {
  // options (optional)
});

Options

httpsOptions

Parameter Type Required Default Description
method 'GET'/'POST'/'PUT'/'PATCH'/'DELETE'/'HEAD'/'CONNECT'/'OPTIONS'/'TRACE' "GET" Provide a method to access the api
headers HTTPHeaders { 'Content-Type': 'application/json' } The header of the request
body Object none The body to send the request (cannot be used in 'GET' request)

Example

  • Default settings

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

// should be inside a async function or have top-level await
await simply.https("postman-echo.com/get");
  • With options

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

simply.https({
  url: "postman-echo.com/get",
  method: "GET",
  headers: { "Content-Type": "application/json" },
});

About

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

License:Other


Languages

Language:TypeScript 100.0%