update tsconfig
This commit is contained in:
parent
bb4a2a660a
commit
a7751006cc
@ -9,12 +9,25 @@
|
|||||||
"githost": "code.foss.global",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "push.rocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "webrequest",
|
"gitrepo": "webrequest",
|
||||||
"description": "securely request from browsers",
|
"description": "A module for making secure web requests from browsers with support for caching and fault tolerance.",
|
||||||
"npmPackagename": "@push.rocks/webrequest",
|
"npmPackagename": "@push.rocks/webrequest",
|
||||||
"license": "MIT"
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"webrequest",
|
||||||
|
"HTTP",
|
||||||
|
"secure",
|
||||||
|
"browsers",
|
||||||
|
"caching",
|
||||||
|
"fault tolerance",
|
||||||
|
"json",
|
||||||
|
"abort",
|
||||||
|
"timeout",
|
||||||
|
"multi-endpoint",
|
||||||
|
"fetch API"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"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"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
15
package.json
15
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "@push.rocks/webrequest",
|
"name": "@push.rocks/webrequest",
|
||||||
"version": "3.0.35",
|
"version": "3.0.35",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "securely request from browsers",
|
"description": "A module for making secure web requests from browsers with support for caching and fault tolerance.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -43,5 +43,18 @@
|
|||||||
],
|
],
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"webrequest",
|
||||||
|
"HTTP",
|
||||||
|
"secure",
|
||||||
|
"browsers",
|
||||||
|
"caching",
|
||||||
|
"fault tolerance",
|
||||||
|
"json",
|
||||||
|
"abort",
|
||||||
|
"timeout",
|
||||||
|
"multi-endpoint",
|
||||||
|
"fetch API"
|
||||||
]
|
]
|
||||||
}
|
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
193
readme.md
193
readme.md
@ -1,37 +1,178 @@
|
|||||||
# @pushrocks/webrequest
|
# @push.rocks/webrequest
|
||||||
securely request from browsers
|
securely request from browsers
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/webrequest)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/webrequest)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/webrequest)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/webrequest/)
|
|
||||||
|
|
||||||
## Status for master
|
To use `@push.rocks/webrequest` in your project, install it using npm or yarn:
|
||||||
|
|
||||||
Status Category | Status Badge
|
```bash
|
||||||
-- | --
|
npm install @push.rocks/webrequest --save
|
||||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/webrequest/badges/master/pipeline.svg)](https://lossless.cloud)
|
# or with yarn
|
||||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/webrequest/badges/master/coverage.svg)](https://lossless.cloud)
|
yarn add @push.rocks/webrequest
|
||||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/webrequest)](https://lossless.cloud)
|
```
|
||||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/webrequest)](https://lossless.cloud)
|
|
||||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
This package is designed to be used in an environment where ECMAScript Modules (ESM) and TypeScript are supported.
|
||||||
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/webrequest)](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/webrequest)](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/webrequest)](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense.
|
`@push.rocks/webrequest` is a powerful module designed to simplify making web requests securely from browsers. It leverages modern JavaScript features and TypeScript for a type-safe development experience. Below are comprehensive examples demonstrating how to utilize the module effectively:
|
||||||
|
|
||||||
## Contribution
|
### Setting Up
|
||||||
|
|
||||||
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). :)
|
First, import `WebRequest` from the module:
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
```typescript
|
||||||
|
import { WebRequest } from '@push.rocks/webrequest';
|
||||||
|
```
|
||||||
|
|
||||||
## Legal
|
Create an instance of `WebRequest`. You can optionally pass configuration options:
|
||||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
```typescript
|
||||||
|
const webRequest = new WebRequest({
|
||||||
|
logging: true // Optional: enables logging, defaults to true
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Making GET Requests
|
||||||
|
|
||||||
|
To fetch JSON data:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Fetch JSON data using GET request
|
||||||
|
async function fetchJsonData() {
|
||||||
|
const url = 'https://api.example.com/data';
|
||||||
|
try {
|
||||||
|
const jsonData = await webRequest.getJson(url);
|
||||||
|
console.log(jsonData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchJsonData();
|
||||||
|
```
|
||||||
|
|
||||||
|
### POST, PUT, and DELETE Requests
|
||||||
|
|
||||||
|
Similarly, you can make POST, PUT, and DELETE requests to send or manipulate data:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Example POST request to submit JSON data
|
||||||
|
async function postJsonData() {
|
||||||
|
const url = 'https://api.example.com/submit';
|
||||||
|
const data = { key: 'value' };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await webRequest.postJson(url, data);
|
||||||
|
console.log(result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
postJsonData();
|
||||||
|
|
||||||
|
// PUT and DELETE can be similarly used
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Caches
|
||||||
|
|
||||||
|
The library provides mechanisms to cache responses, which is useful for reducing network load and improving performance. Here’s how to fetch data with caching:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Fetch with caching enabled
|
||||||
|
async function fetchDataWithCache() {
|
||||||
|
const url = 'https://api.example.com/data';
|
||||||
|
try {
|
||||||
|
// The second parameter enables caching
|
||||||
|
const jsonData = await webRequest.getJson(url, true);
|
||||||
|
console.log(jsonData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchDataWithCache();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Handling Multiple Endpoints
|
||||||
|
|
||||||
|
`@push.rocks/webrequest` supports querying multiple endpoints with fallbacks to handle the situation where some endpoints may fail or be unavailable:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Attempt to request from multiple endpoints
|
||||||
|
async function requestFromMultipleEndpoints() {
|
||||||
|
const endpoints = [
|
||||||
|
'https://api.primary-example.com/data',
|
||||||
|
'https://api.backup-example.com/data'
|
||||||
|
];
|
||||||
|
try {
|
||||||
|
const response = await webRequest.requestMultiEndpoint(endpoints, {
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
console.log(data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to retrieve data from any endpoint', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestFromMultipleEndpoints();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Usage
|
||||||
|
|
||||||
|
For advanced scenarios, you can directly use the `request` method to fully customize the request options including headers, request method, and body (for POST/PUT requests):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Custom request with timeout
|
||||||
|
async function customRequest() {
|
||||||
|
const url = 'https://api.example.com/advanced';
|
||||||
|
try {
|
||||||
|
const response = await webRequest.request(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ custom: 'data' }),
|
||||||
|
timeoutMs: 10000 // Timeout in milliseconds
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
console.log(result);
|
||||||
|
} else {
|
||||||
|
console.error('Response error:', response.status);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Request failed:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customRequest();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
`@push.rocks/webrequest` offers a streamlined, secure way to handle web requests from browsers, supporting various HTTP methods, response caching, and requests to multiple endpoints with fault tolerance. Its TypeScript integration ensures type safety and enhances developer productivity by enabling IntelliSense in supported IDEs.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user