Skip to content

Instantly share code, notes, and snippets.

@persianturtle
Last active September 1, 2021 11:49
Show Gist options
  • Save persianturtle/8ea183176c765a5e2a2fd558cb9b7e7a to your computer and use it in GitHub Desktop.
Save persianturtle/8ea183176c765a5e2a2fd558cb9b7e7a to your computer and use it in GitHub Desktop.
const https = require('https')
const options = {
hostname: 'example.com',
port: 443,
method: 'PUT',
headers: {
'Content-Type': '<whatever>',
Authorization:
'Bearer <token>',
},
path: "/uri/path/here"
}
const response = await new Promise((resolve, reject) => {
const request = https.request(
options,
(response) => {
response.setEncoding('utf8')
let body = ''
response.on('data', (chunk) => {
body += chunk
})
response.on('end', () => {
// if the response is JSON
body = JSON.parse(body)
console.log(body)
})
}
)
request.on('error', reject)
request.end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment