Hyperlocal
🔌 ✨rustlang hyper bindings for local unix domain sockets
Install / Use
/learn @softprops/HyperlocalREADME
Hyper is a rock solid Rust HTTP client and server toolkit.
Unix domain sockets provide a mechanism
for host-local interprocess communication. hyperlocal builds on and complements Hyper's
interfaces for building Unix domain socket HTTP clients and servers.
This is useful for exposing simple HTTP interfaces for your Unix daemons in cases where you want to limit access to the current host, in which case, opening and exposing tcp ports is not needed. Examples of Unix daemons that provide this kind of host local interface include Docker, a process container manager.
Installation
Add the following to your Cargo.toml file
[dependencies]
hyperlocal = "0.9"
Usage
Servers
A typical server can be built by creating a tokio::net::UnixListener and accepting connections in a loop using
hyper::service::service_fn to create a request/response processing function, and connecting the UnixStream to it
using hyper::server::conn::http1::Builder::new().serve_connection().
hyperlocal provides an extension trait UnixListenerExt with an implementation of this.
An example is at examples/server.rs, runnable via cargo run --example server
To test that your server is working you can use an out-of-the-box tool like curl
$ curl --unix-socket /tmp/hyperlocal.sock localhost
It's a Unix system. I know this.
Clients
hyperlocal also provides bindings for writing unix domain socket based HTTP clients the Client interface from the
hyper-utils crate.
An example is at examples/client.rs, runnable via cargo run --example client
Hyper's client interface makes it easy to send typical HTTP methods like GET, POST, DELETE with factory
methods, get, post, delete, etc. These require an argument that can be transformed into a hyper::Uri.
Since Unix domain sockets aren't represented with hostnames that resolve to ip addresses coupled with network ports,
your standard over the counter URL string won't do. Instead, use a hyperlocal::Uri, which represents both file path to the domain
socket and the resource URI path and query string.
Doug Tangren (softprops) 2015-2024
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
