Skip to main content

https

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

Implementation​

simplydjs.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​

simplydjs.https(
url: string | httpsOptions,
options: httpsOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
}
): Promise<any>

Options​

httpsOptions​

ParameterTypeRequiredDefaultDescription
method'GET'/'POST'/'PUT'/'PATCH'/'DELETE'/'HEAD'/'CONNECT'/'OPTIONS'/'TRACE'❌"GET"Provide a method to access the api
headersOutgoingHttpHeaders❌{ 'Content-Type': 'application/json' }The header of the request
bodyObject❌noneThe body to send the request (cannot be used in 'GET' request)
urlstring❌noneThe url to do https request
hoststring❌noneThe host url of the website to do https request (do not use if you are using url option)
endpointstring❌noneThe endpoints of the website to do https request (do not use if you are using url option)
debugboolean❌falseconsole logs every data retreived. Easier to debug if any errors
export type httpsOptions = {
method:
| "GET"
| "POST"
| "PUT"
| "PATCH"
| "DELETE"
| "HEAD"
| "CONNECT"
| "OPTIONS"
| "TRACE";
headers: OutgoingHttpHeaders;
body?: Object;

url?: string;
host?: string;
endpoint?: string;

debug?: boolean;
};

Example​

  • Default settings​

https.js
const simplydjs = require('simply-djs')

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

https.js
const simplydjs = require('simply-djs')

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