Package Exports
- chiaki
- chiaki/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chiaki) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Chiaki
Chiaki is a tiny (300 byte) HTTPs client for NodeJS. It provides a modern asynchronous interface to NodeJS's default https.request
method.
import chiaki from 'chiaki'
await chiaki('https://ifconfig.io')
.then(response => response.body)
.then(response => JSON.parse(response))
Installation
npm i chiaki
Usage
Chiaki can be used similarly to JavaScript's Fetch API. For example, to retrieve the HTML content of a web page:
// Using Fetch.
await fetch('https://example.com')
.then(response => response.text())
// Using Chiaki.
await chiaki('https://example.com')
.then(response => response.body.toString())
You can also provide additional HTTPs options. For example, as part of a POST request:
// Using Fetch.
await fetch('https://example.com/login', {
method: 'POST',
headers: {
'User-Agent': 'foo',
},
body: JSON.stringify({
username: 'bar',
password: 'baz',
}),
})
// Using Chiaki.
await chiaki({
hostname: 'https://example.com',
path: '/login',
headers: {
'User-Agent': 'foo',
},
body: JSON.stringify({
username: 'bar',
password: 'baz',
}),
})
API
chiaki.chiaki(options)
Performs an asynchronous HTTPs request. options
can be a string, URL
or HTTPs options object. Returns a Promise
which resolves to a Response
object. The response contains the following properties:
status
- the response status code.headers
- the response headers as a plain JavaScript object.body
- the response content as aBuffer
. Convert to a string usingbody.toString()
or to JSON usingJSON.parse(body)
.