Comparing version 0.46.0 to 0.47.0
@@ -261,2 +261,13 @@ /// <reference types="node" /> | ||
/** | ||
* Makes a POST HTTP request and uploads a file. Will throw an error if the response status code is not 2xx. | ||
* @param url | ||
* @param sourceFilePath | ||
* @param contentType The media type of the file being uploaded (e.g. "image/png", "application/pdf", "text/plain", etc.) | ||
* @param headers | ||
* @returns | ||
*/ | ||
upload<T_6>(url: string, sourceFilePath: string, contentType: string, headers?: { | ||
[name: string]: string; | ||
}): Promise<T_6 | undefined>; | ||
/** | ||
* Makes a GET HTTP request and saves the response to a file. | ||
@@ -269,5 +280,5 @@ * Will throw an error if the response status code is not 2xx. | ||
*/ | ||
download(url: string, filePath: string, headers?: { | ||
download<T_7>(url: string, destinationFilePath: string, headers?: { | ||
[name: string]: string; | ||
}): Promise<IHttpResponse<any>>; | ||
}): Promise<IHttpResponse<T_7>>; | ||
}; | ||
@@ -274,0 +285,0 @@ /** |
{ | ||
"name": "jsh", | ||
"version": "0.46.0", | ||
"version": "0.47.0", | ||
"description": "Helpers for Bash like shell scripting in JavaScript", | ||
@@ -5,0 +5,0 @@ "author": "Brady Holt", |
@@ -106,4 +106,6 @@ # jsh [![Build](https://github.com/bradymholt/jsh/actions/workflows/build.yml/badge.svg)](https://github.com/bradymholt/jsh/actions/workflows/build.yml) [![NPM Package](https://img.shields.io/npm/v/jsh.svg)](https://www.npmjs.com/package/jsh) | ||
| `await http("POST", "https://www.myapi.com", { data: "1" }, { headers: { Accept: "application/json" } })` | Make a HTTP request and return the response: (`{ data, headers, statusCode, statusMessage }`) | | ||
| `await http.download("https://www.myapp.com/logo.jpg", "./logo.jpg")` | Download a file from a URL and save it to a local file path | | ||
| `await http.upload("https://www.myapi.com/logo", "./logo.jpg", "image/jpg")` | Upload a file with a HTTP POST request | | ||
| `await http.download("https://www.myapp.com/logo.jpg", "./logo.jpg")` | Perform a HTTP GET request and save the response to a local file path | | ||
## Examples | ||
@@ -299,3 +301,3 @@ | ||
#### Stream | ||
You may also pass a readable Stream as `data`. This is common when sending a file as part of a request: | ||
You may also pass a readable Stream as `data`. This is common when sending a file as part of a request. | ||
@@ -309,6 +311,8 @@ ```js | ||
"Content-Type": "image/jpeg", | ||
"Content-Length": fileSize, | ||
"Content-Length": fileSize.toString(), | ||
}); | ||
``` | ||
_Note: If you are uploading a file, you can also use the `http.upload()` helper._ | ||
### Default Headers | ||
@@ -315,0 +319,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84352
1725
543
11