Package Exports
- cowl
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 (cowl) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Cowl
Request cowl for making requests from NodeJS/Browser/React-Native
About
Cowl is a wrapper for HTTP/S requests for use in NodeJS and the browser. React-Native is a work-in-progress. It's designed to be useable from 1 script, support bundling (via Webpack) and support sending and receiving data. It provides a simple API that uses a configuration object to make requests.
Usage
Install it by running npm install cowl.
GET requests can be made by using the configuration object or by simply passing a URL:
const { request } = require("cowl");
request("https://server.com/api").then(/* ... */);
request({
url: "https://server.com/api"
}).then(/* ... */);
request({
url: "https://server.com/api",
method: "GET",
headers: {
"Authorization": "Bearer ..."
}
}).then(/* ... */);By default Cowl will send JSON if an object is passed to the body. It also tries to parse JSON as the response, by default. You can change the response type by setting it to one of RESPONSE_TYPE_BUFFER, RESPONSE_TYPE_JSON or RESPONSE_TYPE_TEXT.
You can of course use "buffer", "json" and "text" for these values, but there's no guarantee that the constant's value will remain the same in future versions of this library.
const { RESPONSE_TYPE_BUFFER, request } = require("cowl");
request({
url: "https://server.com/res/item",
method: "GET",
responseType: RESPONSE_TYPE_BUFFER
}).then(resp => {
// resp.data will be a Buffer on node, and an ArrayBuffer in the browser
});Request objects form the following structure:
| Property | Required | Type | Description |
|---|---|---|---|
url |
Yes | String | The request URL |
method |
No | String | The HTTP request method (default: GET) |
headers |
No | Object | Headers for the request |
query |
No | String | Object |
responseType |
No | String | The response type (default: json) |
Response objects have the following structure:
| Property | Type | Description |
|---|---|---|
url |
String | The resulting URL that the request was made against |
method |
String | The request method used |
headers |
Object | The response headers received |
data |
Object | Buffer |
status |
Number | The status code |
statusCode |
String | The status code text |