usage
install
npm i @splitscript.js/httpsimport
// 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')Last updated
Was this helpful?
