Chapter 4: initial recipe samples
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
const https = require('https')
|
||||
|
||||
// http.get('http://example.com', (res) => res.pipe(process.stdout))
|
||||
|
||||
const payload = `{
|
||||
"name": "Beth",
|
||||
"job": "Software Engineer"
|
||||
}`
|
||||
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
hostname: 'postman-echo.com',
|
||||
path: '/post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(payload)
|
||||
}
|
||||
}
|
||||
|
||||
const req = https.request(opts, (res) => {
|
||||
process.stdout.write('Status Code: ' + res.statusCode + '\n')
|
||||
process.stdout.write('Body: ')
|
||||
res.pipe(process.stdout)
|
||||
})
|
||||
|
||||
req.on('error', (err) => console.error('Error: ', err))
|
||||
|
||||
req.end(payload)
|
||||
Reference in New Issue
Block a user