fix(core): update
This commit is contained in:
parent
9cf8c0b0f3
commit
f55ab55365
@ -12,12 +12,26 @@
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartrequest",
|
||||
"description": "dropin replacement for request",
|
||||
"description": "A module for modern HTTP/HTTPS requests with support for form data, file uploads, JSON, binary data, streams, and more.",
|
||||
"npmPackagename": "@push.rocks/smartrequest",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"request library",
|
||||
"form data",
|
||||
"file uploads",
|
||||
"JSON",
|
||||
"binary data",
|
||||
"streams",
|
||||
"keepAlive",
|
||||
"TypeScript",
|
||||
"modern web requests",
|
||||
"drop-in replacement"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdocs": {
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
17
package.json
17
package.json
@ -2,7 +2,7 @@
|
||||
"name": "@push.rocks/smartrequest",
|
||||
"version": "2.0.21",
|
||||
"private": false,
|
||||
"description": "dropin replacement for request",
|
||||
"description": "A module for modern HTTP/HTTPS requests with support for form data, file uploads, JSON, binary data, streams, and more.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
@ -16,7 +16,18 @@
|
||||
"url": "git+https://gitlab.com/push.rocks/smartrequest.git"
|
||||
},
|
||||
"keywords": [
|
||||
"request"
|
||||
"HTTP",
|
||||
"HTTPS",
|
||||
"request library",
|
||||
"form data",
|
||||
"file uploads",
|
||||
"JSON",
|
||||
"binary data",
|
||||
"streams",
|
||||
"keepAlive",
|
||||
"TypeScript",
|
||||
"modern web requests",
|
||||
"drop-in replacement"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
@ -52,4 +63,4 @@
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
}
|
11
readme.hints.md
Normal file
11
readme.hints.md
Normal file
@ -0,0 +1,11 @@
|
||||
- supports http
|
||||
- supports https
|
||||
- supports unix socks
|
||||
- supports formData
|
||||
- supports file uploads
|
||||
- supports best practice keepAlive
|
||||
- dedicated functions for working with JSON request/response cycles
|
||||
- written in TypeScript
|
||||
- continuously updated
|
||||
- uses node native http and https modules
|
||||
- used in modules like @push.rocks/smartproxy and @api.global/typedrequest
|
219
readme.md
219
readme.md
@ -1,96 +1,139 @@
|
||||
# @pushrocks/smartrequest
|
||||
dropin replacement for request
|
||||
# @push.rocks/smartrequest
|
||||
A module providing a drop-in replacement for the deprecated Request library, focusing on modern HTTP/HTTPS requests with support for form data, file uploads, JSON, binary data, and streams.
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartrequest)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartrequest)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartrequest)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartrequest/)
|
||||
## Install
|
||||
To install `@push.rocks/smartrequest`, use the following npm command:
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartrequest/badges/master/pipeline.svg)](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartrequest/badges/master/coverage.svg)](https://lossless.cloud)
|
||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartrequest)](https://lossless.cloud)
|
||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartrequest)](https://lossless.cloud)
|
||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartrequest)](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartrequest)](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartrequest)](https://lossless.cloud)
|
||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
### Features
|
||||
|
||||
- supports http
|
||||
- supports https
|
||||
- supports unix socks
|
||||
- supports formData
|
||||
- supports file uploads
|
||||
- supports best practice keepAlive
|
||||
- dedicated functions for working with JSON request/response cycles
|
||||
- written in TypeScript
|
||||
- continuously updated
|
||||
- uses node native http and https modules
|
||||
- used in modules like @pushrocks/smartproxy and @apiglobal/typedrequest
|
||||
- commercial support available at [https://lossless.support](https://lossless.support)
|
||||
|
||||
> note: smartrequest uses the **native** node http/https modules under the hood (not the bloated one from npm)
|
||||
|
||||
```javascript
|
||||
import * as smartrequest from 'smartrequest'
|
||||
|
||||
// simple post
|
||||
const options: smartrequest.ISmartRequestOptions = { // typed options
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
"Authorization": "Bearer token"
|
||||
},
|
||||
requestBody: JSON.stringify({
|
||||
key1: 'value1',
|
||||
key2: 3
|
||||
})
|
||||
}
|
||||
|
||||
smartrequest.request('https://example.com', options).then(res => {
|
||||
console.log(res.status)
|
||||
console.log(res.body) // if json, body will be parsed automatically
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
// dedicated JSON methods are available:
|
||||
smartrequest.getJson(...)
|
||||
smartrequest.postJson(...)
|
||||
smartrequest.putJson(...)
|
||||
smartrequest.delJson(...)
|
||||
|
||||
// streaming
|
||||
smartrequest.get('https://example.com/bigfile.mp4', optionsArg, true).then(res => { // third arg = true signals streaming
|
||||
console.log(res.status)
|
||||
res.on('data', data => {
|
||||
// do something with the data chunk here
|
||||
}
|
||||
res.on('end', () => {
|
||||
// do something when things have ended
|
||||
})
|
||||
})
|
||||
```bash
|
||||
npm install @push.rocks/smartrequest --save
|
||||
```
|
||||
|
||||
## Contribution
|
||||
This command will add `@push.rocks/smartrequest` to your project's dependencies.
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
## Usage
|
||||
`@push.rocks/smartrequest` is designed as a versatile, modern HTTP client library for making HTTP/HTTPS requests. It supports a range of features, including handling form data, file uploads, JSON requests, binary data, streaming, and much more, all within a modern, promise-based API.
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
Below we will cover key usage scenarios of `@push.rocks/smartrequest`, showcasing its capabilities and providing you with a solid starting point to integrate it into your projects.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
### Simple GET Request
|
||||
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
For fetching data from a REST API or any web service that returns JSON:
|
||||
|
||||
```typescript
|
||||
import { getJson } from '@push.rocks/smartrequest';
|
||||
|
||||
async function fetchGitHubUserInfo(username: string) {
|
||||
const response = await getJson(`https://api.github.com/users/${username}`);
|
||||
console.log(response.body); // The body contains the JSON response
|
||||
}
|
||||
|
||||
fetchGitHubUserInfo('octocat');
|
||||
```
|
||||
|
||||
The `getJson` function simplifies the process of sending a GET request and parsing the JSON response.
|
||||
|
||||
### POST Requests with JSON
|
||||
|
||||
When you need to send JSON data to a server, for example, creating a new resource:
|
||||
|
||||
```typescript
|
||||
import { postJson } from '@push.rocks/smartrequest';
|
||||
|
||||
async function createTodoItem(todoDetails: { title: string; completed: boolean }) {
|
||||
const response = await postJson('https://jsonplaceholder.typicode.com/todos', {
|
||||
requestBody: todoDetails
|
||||
});
|
||||
console.log(response.body); // Log the created todo item
|
||||
}
|
||||
|
||||
createTodoItem({ title: 'Implement smartrequest', completed: false });
|
||||
```
|
||||
|
||||
`postJson` handles setting the appropriate content-type header and stringifies the JSON body.
|
||||
|
||||
### Handling Form Data and File Uploads
|
||||
|
||||
`@push.rocks/smartrequest` simplifies the process of uploading files and submitting form data to a server:
|
||||
|
||||
```typescript
|
||||
import { postFormData, IFormField } from '@push.rocks/smartrequest';
|
||||
|
||||
async function uploadProfilePicture(formDataFields: IFormField[]) {
|
||||
await postFormData('https://api.example.com/upload', {}, formDataFields);
|
||||
}
|
||||
|
||||
uploadProfilePicture([
|
||||
{ name: 'avatar', type: 'filePath', payload: './path/to/avatar.jpg', fileName: 'avatar.jpg', contentType: 'image/jpeg' },
|
||||
{ name: 'user_id', type: 'string', payload: '12345' }
|
||||
]);
|
||||
```
|
||||
|
||||
### Streaming Support
|
||||
|
||||
For cases when dealing with large datasets or streaming APIs, `@push.rocks/smartrequest` provides streaming capabilities:
|
||||
|
||||
```typescript
|
||||
import { getStream } from '@push.rocks/smartrequest';
|
||||
|
||||
async function streamLargeFile(url: string) {
|
||||
const stream = await getStream(url);
|
||||
|
||||
stream.on('data', (chunk) => {
|
||||
console.log('Received chunk of data.');
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
console.log('Stream ended.');
|
||||
});
|
||||
}
|
||||
|
||||
streamLargeFile('https://example.com/largefile');
|
||||
```
|
||||
|
||||
`getStream` allows you to handle data as it's received, which can be beneficial for performance and scalability.
|
||||
|
||||
### Advanced Options and Customization
|
||||
|
||||
`@push.rocks/smartrequest` is built to be flexible, allowing you to specify additional options to tailor requests to your needs:
|
||||
|
||||
```typescript
|
||||
import { request, ISmartRequestOptions } from '@push.rocks/smartrequest';
|
||||
|
||||
async function customRequestExample() {
|
||||
const options: ISmartRequestOptions = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Custom-Header': 'Value'
|
||||
},
|
||||
keepAlive: true // Enables connection keep-alive
|
||||
};
|
||||
|
||||
const response = await request('https://example.com/data', options);
|
||||
console.log(response.body);
|
||||
}
|
||||
|
||||
customRequestExample();
|
||||
```
|
||||
|
||||
`request` is the underlying function that powers the simpler `getJson`, `postJson`, etc., and provides you with full control over the HTTP request.
|
||||
|
||||
Through its comprehensive set of features tailored for modern web development, `@push.rocks/smartrequest` aims to provide developers with a powerful tool for handling HTTP/HTTPS requests efficiently. Whether it's a simple API call, handling form data, or processing streams, `@push.rocks/smartrequest` delivers a robust, type-safe solution to fit your project's requirements.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartrequest',
|
||||
version: '2.0.21',
|
||||
description: 'dropin replacement for request'
|
||||
version: '2.0.22',
|
||||
description: 'A module for modern HTTP/HTTPS requests with support for form data, file uploads, JSON, binary data, streams, and more.'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user