@npy/fetch 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 matheus fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @npy/fetch
2
+
3
+ an http/1.1 client built over raw tcp sockets with a fetch-compatible api, per-origin connection pooling, and first-class proxy support.
4
+
5
+ > [!NOTE]
6
+ > node and bun only — does not work in the browser.
7
+
8
+ ## install
9
+ ```sh
10
+ bun add @npy/fetch
11
+ # or
12
+ npm install @npy/fetch
13
+ ```
14
+
15
+ ## usage
16
+
17
+ ### simple fetch
18
+ ```ts
19
+ import { fetch } from '@npy/fetch'
20
+
21
+ const response = await fetch('https://httpbin.org/anything')
22
+ const body = await response.json()
23
+ console.log(body)
24
+
25
+ fetch.close()
26
+ ```
27
+
28
+ ### with http/s proxy
29
+ ```ts
30
+ import { createFetch, HttpClient } from '@npy/fetch'
31
+ import { ProxyDialer } from '@npy/fetch/dialers'
32
+
33
+ const fetch = createFetch(new HttpClient({
34
+ dialer: new ProxyDialer('http://user:pass@proxy.example.com:8080'),
35
+ }))
36
+
37
+ const response = await fetch('https://httpbin.org/ip')
38
+ console.log(await response.json())
39
+
40
+ fetch.close()
41
+ ```
42
+
43
+ ### with socks proxy
44
+ ```ts
45
+ import { createFetch, HttpClient } from '@npy/fetch'
46
+ import { ProxyDialer } from '@npy/fetch/dialers'
47
+
48
+ const fetch = createFetch(new HttpClient({
49
+ dialer: new ProxyDialer('socks5://user:pass@proxy.example.com:1080'),
50
+ }))
51
+
52
+ const response = await fetch('https://httpbin.org/ip')
53
+ console.log(await response.json())
54
+
55
+ fetch.close()
56
+ ```
57
+
58
+ ### custom i/o options
59
+ ```ts
60
+ import { HttpClient } from '@npy/fetch'
61
+
62
+ const client = new HttpClient({
63
+ poolMaxPerHost: 10,
64
+ poolMaxIdlePerHost: 5,
65
+ poolIdleTimeout: 30_000,
66
+ connect: {
67
+ keepAlive: true,
68
+ noDelay: true,
69
+ timeout: 5_000,
70
+ },
71
+ io: {
72
+ reader: {
73
+ bufferSize: 32 * 1024,
74
+ highWaterMark: 16 * 1024,
75
+ maxHeaderSize: 16 * 1024,
76
+ maxBodySize: '10mb',
77
+ decompress: true,
78
+ },
79
+ writer: {
80
+ highWaterMark: 16 * 1024,
81
+ coalesceBodyMaxBytes: 64 * 1024,
82
+ },
83
+ },
84
+ })
85
+
86
+ const response = await client.send({ url: 'https://httpbin.org/anything', method: 'GET' })
87
+ console.log(await response.json())
88
+
89
+ await client.close()
90
+ ```
91
+
92
+ ### using `HttpClient` directly
93
+ ```ts
94
+ import { HttpClient } from '@npy/fetch'
95
+
96
+ const client = new HttpClient()
97
+
98
+ const response = await client.send({
99
+ url: 'https://httpbin.org/post',
100
+ method: 'POST',
101
+ headers: new Headers({ 'content-type': 'application/json' }),
102
+ body: JSON.stringify({ hello: 'world' }),
103
+ })
104
+
105
+ console.log(await response.json())
106
+ await client.close()
107
+ ```
108
+
109
+ ---
110
+
111
+ based on [deno-simple-fetch](https://github.com/esroyo/deno-simple-fetch).
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@npy/fetch",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "scripts": {},
7
+ "dependencies": {
8
+ "@fuman/io": "^0.0.19",
9
+ "@fuman/net": "^0.0.19",
10
+ "@fuman/node": "^0.0.19",
11
+ "@fuman/utils": "^0.0.19",
12
+ "@npy/proxy-kit": "0.1.0",
13
+ "bytes": "^3.1.2",
14
+ "generic-pool": "^3.9.0",
15
+ "mitata": "^1.0.34"
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "import": {
20
+ "types": "./index.d.ts",
21
+ "default": "./index.js"
22
+ },
23
+ "require": {
24
+ "types": "./index.d.cts",
25
+ "default": "./index.cjs"
26
+ }
27
+ }
28
+ },
29
+ "sideEffects": false,
30
+ "files": [
31
+ "dist",
32
+ "LICENSE",
33
+ "README.md"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/neeopy/npy.git"
38
+ }
39
+ }