SwiftPie is a Swift-native, HTTPie-compatible CLI for making HTTP requests. It mirrors HTTPie's concise argument syntax, integrates with Swift's swift-http-types, and provides a clean transport abstraction so the CLI can target different execution environments.
Sources/SwiftPie— Reusable core library with request parsing, transport abstraction, and response formatting.Sources/SwiftPieCLI— Production command-line tool that performs real network traffic usingURLSessionTransport.Examples/PeerDemo— Minimal CLI showcasing the new peer-mode (PeerTransport) that executes requests directly against Swift responders without opening a socket.Tests/SwiftPieTests— Unit and integration tests covering CLI flows, transports, and the reusable request parser.Tests/TestSupport— In-process HTTP server and shared responders used by tests and examples.
Requires Swift 6.2+ on macOS 14:
swift build
swift testA convenience smoke script rebuilds the package and runs both executables:
scripts/smoke-cli.sh
The primary executable mirrors HTTPie's syntax. For example:
swift run spie https://httpbin.org/get foo=bar
Add headers or JSON payloads using familiar HTTPie shorthands:
swift run spie POST https://httpbin.org/post Authorization:"Bearer token" flag:=true message="hello"
- Plain
key=valuepairs are serialized into a JSON object by default. Switch to URL-encoded forms with--formor send an opaque payload with--raw(accepting inline strings,@/path/to/body, or@-for stdin). - Embed file contents in structured payloads with
field=@/path/to/text.txtorfield:=@/path/to/data.json; headers can read from files viaHeader:@secrets/token.txt. - Stdin shorthands work across headers, data fields, and raw bodies using
@-, enabling pipelines such ascat payload.json | swift run spie --raw=@- POST https://api.example.com.
- Follow redirect chains with
--follow(or-F) and tune hop limits via--max-redirects. - Add
--check-statusto exit with HTTP-aware codes (3 for redirect without follow, 4 for client errors, 5 for server errors) while emitting warnings on stderr.
Peer mode lets the CLI forward requests directly to Swift responders without a network hop. The core pieces are:
import SwiftPie SwiftPie.main { request in var headers = HTTPFields() headers[.contentType] = "text/plain; charset=utf-8" let response = HTTPResponse(status: .ok, headerFields: headers) return ResponsePayload(response: response, body: .text("peer response")) }
Pair it with Vapor or custom responders to embed HTTP workflows directly inside your CLI. To bootstrap quickly, run the included peer demo:
swift run PeerDemo /get foo=bar
PeerDemo reuses the same responders that power the in-process test server, showing how production server logic can be shared with tooling.
API documentation lives in Docs/SwiftPie.docc and can be generated with:
swift package generate-documentation --target SwiftPieDocs
The docs cover the core library as well as the new peer-mode interfaces.
SwiftPie is available under the BSD 3-Clause License. See LICENSE and NOTICES for details.