Zero-copy HTTP protocol for the web
npm install @hazae41/fleche
``bash`
npm i @hazae41/fleche
- Reusable underlying connection$3
- Relies on the above HTTP
- Powered by WebAssembly
- Same API than native
- Only 0.3ms slower than native$3
- More HTTP 1.1 features
- HTTP 2, HTTP 3 (QUIC)Usage
`tsx
import { Opaque, Writable } from "@hazae41/binary"
import { fetch } from "@hazae41/fleche"function example(stream: ReadableWritablePair) {
/**
* Fetch using the underlying TCP or TLS stream
*/
const res = await fetch("https://example.com", { stream })
if (!res.ok)
throw new Error(await res.text())
return await res.json()
}
```tsxfunction example(stream: ReadableWritablePair
const socket = new WebSocket("wss://example.com")
/**
* Pipe TCP or TLS input to WebSocket input
*/
stream.readable
.pipeTo(socket.inner.writable, { preventCancel: true })
.catch(() => {})
/**
* Pipe WebSocket output to TCP or TLS output
*/
socket.inner.readable
.pipeTo(stream.writable, { preventClose: true, preventAbort: true })
.catch(() => {})
await new Promise((ok, err) => {
socket.addEventListener("open", ok)
socket.addEventListener("error", err)
})
socket.addEventListener("message", e => console.log(e.data))
socket.send("Hello world")
}