https://github.com/hazae41/fleche
Zero-copy HTTP protocol for the web 🏎️ (JS + WebAssembly)
https://github.com/hazae41/fleche
browser deno fetch gzip http javascript protocol quic rpc typescript webassembly webstream webstreams zero-copy
Last synced: 10 months ago
JSON representation
Zero-copy HTTP protocol for the web 🏎️ (JS + WebAssembly)
- Host: GitHub
- URL: https://github.com/hazae41/fleche
- Owner: hazae41
- Created: 2023-01-07T17:55:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-01T15:52:12.000Z (over 1 year ago)
- Last Synced: 2025-02-19T09:21:14.000Z (11 months ago)
- Topics: browser, deno, fetch, gzip, http, javascript, protocol, quic, rpc, typescript, webassembly, webstream, webstreams, zero-copy
- Language: TypeScript
- Homepage:
- Size: 772 KB
- Stars: 12
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
```bash
npm i @hazae41/fleche
```
[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/fleche)
## Features
### Goals
- 100% TypeScript and ESM
- Zero-copy reading and writing
- Transport agnostic (TCP, TLS, Tor)
- Supports backpressure
### HTTP
- HTTP 1.1
- Native Gzip and Deflate compression
- Compatible with code using `fetch`
- Reusable underlying connection
### WebSocket
- Relies on the above HTTP
- Powered by WebAssembly
- Same API than native
- Only 0.3ms slower than native
### [Upcoming features](https://github.com/sponsors/hazae41)
- 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()
}
```
```tsx
import { Opaque, Writable } from "@hazae41/binary"
import { WebSocket } from "@hazae41/fleche"
function 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")
}