- Overview
- Status
- Dependencies
- Quick Start
- API Reference
- TLS Options
- Testing
- Examples
- Development
- Architecture
- Related Projects
- License
- Contributing
- Changelog
spork-https provides HTTPS support for spork's HTTP client using jsec for TLS encryption. It is a thin wrapper that demonstrates the stream-factory pattern in spork, enabling HTTPS requests through pluggable transport mechanisms.
- Simple HTTPS client API (
https/get,https/post, etc.) - HTTPS server support with TLS encryption
- Full TLS support via jsec
- Certificate verification
- Custom TLS options (ciphers, versions, client certificates, mTLS)
- Compatible with spork's HTTP API
- Works with Janet's
withmacro for automatic cleanup
Functional - The library works for basic HTTPS client/server use cases.
jpm install spork-https
(import spork-https :as https)
# Simple HTTPS GET
(let [response (https/get "https://example.com/")]
(pp (:status response))
(pp (length (:body response))))
# HTTPS POST with body
(https/post "https://api.example.com/data"
:body "{\"key\": \"value\"}"
:headers {"Content-Type" "application/json"})
(https/get url &keys opts)
Make an HTTPS GET request.
url- HTTPS URL string (must start with https://)opts- Optional keyword arguments::headers- Request headers table:tls-opts- TLS options (see TLS Options)
Response table with:
:status- HTTP status code (integer):headers- Response headers table:body- Response body (buffer):connection- TLS stream:buffer- Internal buffer
(import spork-https :as https)
(let [res (https/get "https://example.com/")]
(assert (= (:status res) 200))
(print "Body length: " (length (:body res))))
(https/post url &keys opts)
Make an HTTPS POST request.
url- HTTPS URL stringopts- Optional keyword arguments::body- Request body (string or buffer):headers- Request headers table:tls-opts- TLS options
(https/post "https://api.example.com/submit"
:body "data=value"
:headers {"Content-Type" "application/x-www-form-urlencoded"})
(https/put url &keys opts)
Make an HTTPS PUT request. Parameters same as https/post.
(https/patch url &keys opts)
Make an HTTPS PATCH request. Parameters same as https/post.
(https/delete url &keys opts)
Make an HTTPS DELETE request.
(https/head url &keys opts)
Make an HTTPS HEAD request.
(https/request method url &keys opts)
Make an HTTPS request with specified method.
method- HTTP method string ("GET", "POST", etc.)url- HTTPS URL stringopts- Optional keyword arguments (see above)
(https/server handler cert key &opt host port tls-opts)
Create an HTTPS server that handles incoming requests with TLS encryption.
handler- Request handler function (same signature as spork/http)- Receives request table with
:headers,:path,:method,:body - Returns response table with
:status,:headers,:body
- Receives request table with
cert- Server certificate (PEM string or file path)key- Server private key (PEM string or file path)host- Host to bind to (default "0.0.0.0")port- Port to bind to (default "8443")tls-opts- Optional TLS configuration table (see TLS Options)
(import spork-https :as https)
(import jsec/cert)
# Generate certificate and key
(let [result (cert/generate-self-signed-cert
{:common-name "localhost"
:organization "Test"
:country "US"
:days-valid 365
:bits 2048})
cert (result :cert)
pkey (result :key)]
# Create handler
(defn handler [req]
(case (req :method)
"GET" {:status 200
:headers {"Content-Type" "text/plain"}
:body "Hello, HTTPS!"}
{:status 405
:headers {"Content-Type" "text/plain"}
:body "Method Not Allowed"}))
# Start server
(def server (https/server handler cert pkey "0.0.0.0" "8443"))
# Server runs until closed
(ev/sleep 60)
(:close server))
The :tls-opts table accepts the following keys:
| Option | Type | Description |
|---|---|---|
:verify |
boolean | Verify server certificate (default: true) |
:ca |
string | Path to CA certificate file for verification |
:cert |
string | Client certificate for mTLS |
:key |
string | Client private key for mTLS |
:security |
table | Security options (TLS versions, ciphers, etc.) |
(https/get "https://example.com/"
:tls-opts {:security {:min-version "TLS1.2"
:max-version "TLS1.3"
:ciphers "HIGH:!aNULL"}})
spork-https uses assay for testing.
# Run all tests
janet test/runner.janet # options like verbosity go here (ex: --verbosity 6)
# Clean build and test
jpm clean && jpm build && jpm test
The test suite covers:
- HTTPS client tests (GET, POST, PUT, PATCH, DELETE)
- HTTPS server tests (request handling, TLS handshake, concurrent clients)
- Stream factory integration tests
- Certificate generation tests
Runnable examples are in the examples/ directory:
| File | Description |
|---|---|
simple-server.janet |
HTTPS server with self-signed cert |
simple-client.janet |
HTTPS client requests |
local-test.janet |
Client/server without network |
(import spork-https :as https)
(let [res (https/get "https://api.github.com/users/janet-lang")]
(when (= (:status res) 200)
(print "Success!")
(print (:body res))))
(import spork-https :as https)
(import spork/json)
(let [payload (json/encode {:name "test" :value 42})
res (https/post "https://api.example.com/data"
:body payload
:headers {"Content-Type" "application/json"})]
(print "Status: " (:status res)))
You can use spork's http module directly with jsec as the stream factory:
(import spork/http)
(import jsec/tls :as tls)
(let [res (http/request "GET" "https://example.com/"
:stream-factory tls/connect)]
(pp (:status res)))
jpm run format-janet # Format Janet source files
jpm run format # Format all code
jpm run gen-docs # Generate markdown from org files
jpm run clean-gen # Clean generated files
spork-https is a thin wrapper that:
- Creates a TLS stream factory function with jsec
- Passes this factory to spork's
http/requestvia:stream-factory - Merges TLS options from
:tls-optsinto the factory
This design keeps spork transport-agnostic while enabling HTTPS through optional extensions.
- spork - Janet utilities and HTTP client
- jsec - TLS/SSL support for Janet via OpenSSL
- janet-assay - Testing framework for Janet
- Janet - The Janet programming language
ISC License - see LICENSE file
Issues and pull requests welcome at https://github.com/llmII/spork-https. Tickets and patches (fossil, preferred) at https://code.amlegion.org/spork-https.
See NEWS.org for version history.