SplitScript.js
discordnpmgithub
  • 👋Welcome to SplitScript.js
  • 🍎core
    • root
    • cli
    • EventEmitter
    • Handling Errors
  • 🤖discord
    • getting started
    • create your first project
    • automod
    • bans
    • channels
    • commands
    • emojis
    • followups
    • types
  • 🌐https
    • usage
    • changelog
  • 🔗Links
    • Discord
    • NPM
    • GitHub
Powered by GitBook
On this page
  • install
  • import
  • send a request
  • send a body
  • send URL params
  • send a request with a method

Was this helpful?

Edit on GitHub
  1. https

usage

install

npm i @splitscript.js/https

import

// commonjs
const https = require('@splitscript.js/https');

// esm
import https from '@splitscript.js/core'

send a request

await https.request(url: string, options: Request)

example

// Send a GET request to https://httpbin.org/anything?hello="world"
const request = await https.request('https://httpbin.org/anything');
console.log(request.res)
// A https.IncomingMessage
console.log(request.data)
/*
{
  args: { hello: '"world"' },
  data: '',
  files: {},
  form: {},
  headers: {
    Host: 'httpbin.org'
  },
  json: null,
  method: 'GET',
  origin: '***.**.***.**',
  url: 'https://httpbin.org/anything'
}
*/

send a body

await https.request('https://example.com', {body: 'this is a body!'})

send URL params

// send a request to 'https://example.com?hello=world
await https.request('https://example.com', { params: { hello: 'world' } })

send a request with a method

You can specify method in your config like this:

await https.request('https://example.com', { method: 'POST' })

or you can use https.<method> like this:

await https.get('https://example.com')
await https.post('https://example.com')
await https.put('https://example.com')
await https.patch('https://example.com')
await https.delete('https://example.com')
PrevioustypesNextchangelog

Last updated 2 years ago

Was this helpful?

🌐