AtlatestRepositorysigil-http
1# sigil-http
2
3HTTP/1.1 client and server library for [Sigil](https://codeberg.org/sigil/sigil).
4
5Provides HTTP/1.1 support for building web applications and APIs. Primary
6use cases are serving documentation sites and game server APIs.
7
8This package was extracted from the sigil monorepo — the in-tree history
9under `packages/sigil-http/` is preserved here as `master`.
11## Usage
13```scheme
14(import (sigil http))
16;; Client — GET / POST / PUT / DELETE
17(let ((response (http-get "https://example.com/")))
18 (display (http-response-body response)))
20(http-post "https://api.example.com/users"
21 "{\"name\":\"Alice\"}"
22 '(("Content-Type" . "application/json")))
24;; Server
25(http-serve
26 port: 8080
27 handler: (lambda (request)
28 (http-response 200 '(("Content-Type" . "text/plain"))
29 "Hello, world!")))
30```
32See `docs/http.md` for the full API reference, including streaming bodies,
33Server-Sent Events, and low-level request/response manipulation.
35## Binary uploads
37`(sigil http client)` exports `http-fetch-bytes`. Its `body:` argument
38accepts a string or bytevector; use bytevectors for images and other binary data.
39The response has `status:`, an ordered `headers:` alist, and bytevector `body:`.
40Redirects are returned to the caller and transport failures return `#f`.
42```scheme
43(import (sigil http client))
44(http-fetch-bytes 'PUT "https://example.com/object"
45 headers: #{ content-type: "application/octet-stream" }
46 body: image-bytes timeout: 30)
47```
49Run `node test/integration/run-upload-tests.mjs` (Node 18+) for the full Sigil
50suite plus an ephemeral loopback server exercising empty and 2 MB binary bodies.
52## Dependencies
54- `sigil-stdlib`, `sigil-socket`, `sigil-tls` — pinned via `from-git`
55 against the sigil monorepo (`^0.13.1`). Resolved automatically by
56 `sigil deps install`.
58## Build
60```bash
61sigil deps install
62sigil build
63sigil test
64```
66## Development against a local sigil checkout
68`dev-redirects.sgl` redirects `codeberg:sigil/sigil` to `../sigil`. Pass
69it to the build CLI when you need to test against unreleased monorepo
70changes:
72```bash
73sigil build --redirects dev-redirects.sgl
74```
76Otherwise, let `sigil deps install` pull the pinned monorepo tag.
78## License
80BSD-3-Clause. See `package.sgl` for author list.
82### Binary multipart forms
84`parse-form-data` prefers a request's raw bytes for multipart input. File parts
85return a bytevector in `content:`; ordinary fields are independently decoded as
86UTF-8. Consumers that previously treated uploaded file content as text should
87decode explicitly only for text formats. `parse-multipart-form-data-bytes` is
88also available directly. It requires CRLF framing and a closing delimiter, with
89a maximum of 128 parts and 16 KiB of headers per part. The server request-size
90limit still controls the total body. The older string parser remains available.