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 totop-level await
Types
simplydjs.https(
url: string | httpsOptions,
options: httpsOptions = {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
}
): Promise<any>
- url:
string
|httpsOptions
- options:
httpsOptions
- Resolves:
any
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 | OutgoingHttpHeaders | ❌ | { 'Content-Type': 'application/json' } | The header of the request |
body | Object | ❌ | none | The body to send the request (cannot be used in 'GET' request) |
url | string | ❌ | none | The url to do https request |
host | string | ❌ | none | The host url of the website to do https request (do not use if you are using url option) |
endpoint | string | ❌ | none | The endpoints of the website to do https request (do not use if you are using url option) |
debug | boolean | ❌ | false | console 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' }
})