Crystal port of lostisland/faraday — an HTTP client library abstraction layer with Rack-inspired middleware. Transpiled with alexanderadam/ruby_to_crystal.
Add to your shard.yml:
dependencies:
faraday:
github: crystal-ports/faradayThen run shards install.
require "faraday"
conn = Faraday.new(url: "https://api.example.com") do |f|
f.request :json
f.response :json
f.response :raise_error
f.adapter :net_http
end
response = conn.get("/users")
response.body # => parsed Hashconn = Faraday.new(url: "https://api.example.com") do |f|
f.request :authorization, "Bearer", "my-token"
f.request :url_encoded
f.response :logger
f.response :raise_error
f.adapter :net_http
endAvailable middleware:
- Request:
:authorization,:json,:url_encoded,:instrumentation - Response:
:json,:logger,:raise_error
conn = Faraday.new do |f|
f.adapter :test do |stub|
stub.get("/hello") { [200, {"Content-Type" => "text/plain"}, "world"] }
stub.post("/data") { |env| [201, {}, env.request_body] }
end
end
conn.get("/hello").body # => "world"The only bundled adapter is :net_http (Crystal stdlib HTTP::Client). It is the default.
Crystal ≥ 1.14.0.
shards install
crystal spec
# 110 examples, 0 failures
- Parallel request support —
env.parallel?always returnsfalse - Non-stdlib adapters (Typhoeus, Excon, etc.)
- Multipart / file upload (
Faraday::UploadIO)
See .claude/CLAUDE.md for the architecture overview, directory map,
middleware/adapter implementation patterns, and Crystal-specific decisions.
The source files were git mv'd from their Ruby paths to Crystal paths, so the full Ruby commit
history is reachable via git log --follow src/faraday/foo.cr.
© 2009 - 2023, the Faraday Team. Crystal port by crystal-ports.