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
bodyObjectnoneThe body to send the request (cannot be used in 'GET' request)
urlstringnoneThe url to do https request
hoststringnoneThe host url of the website to do https request (do not use if you are using url option)
endpointstringnoneThe endpoints of the website to do https request (do not use if you are using url option)
debugbooleanfalseconsole 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' }
})