Here is a production bug you can reproduce in four lines of Crystal:
| |
Crystal’s standard library HTTP client does not follow redirects and does not raise on a 500. It returns a response object and lets you decide what it means. That is a defensible design for a language runtime, and a genuinely dangerous default for application code: a misconfigured base URL turns into an empty list instead of an exception, and your monitoring stays green while the feature is silently dead.
The three options in this comparison differ mainly in how much of that responsibility they take off your hands. Quick verdict: reach for Crest for application HTTP calls that touch third-party services, use the stdlib HTTP::Client for internal, well-understood endpoints or when you cannot add dependencies, and consider Halite only if you specifically need its middleware and session model — it has not been released since 2022.
The Three Contenders at a Glance
| Criterion | stdlib HTTP::Client | Crest | Halite |
|---|---|---|---|
| Version | Ships with Crystal | 1.9.0 | 0.12.1 |
| GitHub stars | Crystal itself: 20,530 | 249 | 171 |
| Last commit | Dec 2026 (language) | Nov 2026 | Mar 2022 |
| License | Apache-2.0 (Crystal) | MIT | MIT |
| External shard dependencies | None | 3 (cookie_jar, http_proxy, digest auth) | None |
| Follows redirects | No | Yes, 10 by default, with response.history | Yes, configurable |
| Raises on 4xx/5xx | No | Yes by default (Crest::RequestFailed) | Yes (Halite::ClientError / ServerError) |
| Query params helper | Manual | Yes (params:) | Yes (params:) |
| JSON request helper | Manual | Yes (json: true) | Yes (json:) |
| Multipart uploads | Manual | Yes | Yes |
| Cookie jar / sessions | Manual | Cookie jar support | Built-in session object |
| Middleware hooks | None | Logging, custom clients | Feature registration and interception |
| Default timeouts | None | None unless specified | None unless specified |
Two of these three ship no timeout by default, and that is the single most common way a Crystal service hangs in production. We will come back to it.
Decision Matrix: Ten Seconds to a Choice
| Your situation | Pick | Why |
|---|---|---|
| Calling Stripe, GitHub, or any third-party REST API | Crest | Redirect following, error raising, JSON helpers, timeouts in one call |
| Internal service call with a known-good URL | stdlib | Zero dependencies, zero abstraction, predictable |
| Long-lived client with cookies and login flow | Halite | Session object with persistent state |
| You need request interception for tracing | Halite or Crest | Halite has explicit features; Crest exposes logging and custom clients |
| Shipping a static binary in a minimal container | stdlib or Halite | Crest pulls three extra shards |
| Codebase that must stay on a maintained dependency | Crest | Only actively developed option of the two shards |
| Downloading large files with progress | Crest or stdlib streaming | Both support streaming bodies; Halite is stale |
stdlib HTTP::Client — Small, Fast, and Entirely Your Problem
The standard library client is a thin wrapper over sockets. You construct a client, reuse it, and close it.
| |
A POST with a JSON body is still manual, but not painful:
| |
The performance story is the good part. HTTP::Client keeps the connection open between requests, so a loop of 100 calls on one client instance negotiates TLS once. Constructing a new client per request throws that away and adds a full handshake to every call — a difference you can measure in tens of milliseconds per request against a remote host.
The correctness story is the bad part. Everything the stdlib does not do is now your job:
| |
That snippet is already wrong for 307 and 308 (method must be preserved) and for relative Location headers. This is the exact category of code that Crest exists to delete from your application.
Crest — The Pragmatic Application Client
Crest wraps the stdlib client with the behaviors application code expects: redirect following, exception raising on HTTP errors, query parameter encoding, JSON requests, multipart uploads, proxies, cookie jars, and per-request timeouts.
| |
| |
A JSON POST collapses to one call:
| |
Error handling is the reason most teams adopt it. With the default handle_errors: true, any 4xx or 5xx raises Crest::RequestFailed, which carries the response:
| |
Set handle_errors: false when a 404 is a normal branch rather than a failure, and Crest returns the response instead of raising. Redirects are followed up to max_redirects (default 10), and response.history gives you the chain of responses — useful when a partner API starts bouncing you through a login flow.
Multipart uploads and streaming downloads are supported directly:
| |
The tradeoff is dependency surface: Crest pulls in cookie_jar, http_proxy, and http-client-digest_auth. For a static binary in a scratch container, that is three more shards to compile — not a problem, but not nothing.
Halite — Sessions, Middleware, and a Maintenance Question
Halite models itself on Python’s requests. It has a chainable API, a built-in session, response MIME adapters, and a feature-registration system that acts as middleware.
| |
| |
The session object is the feature that distinguishes it. Cookies and headers persist across requests when you configure them through Halite::Options, which makes login-then-scrape flows shorter than the equivalent stdlib code:
| |
The middleware system registers named features that can inspect and mutate requests and responses — the documented example registers a feature that rewrites a 404 into something else. If you have ever wanted a request-level tracing hook in Crystal without forking a client, this is the closest thing available.
The problem is time. Halite’s newest release, 0.12.1, dates to 2022, and the repository’s last commit was March 2022. It declares support for Crystal >= 0.36.1, < 2.0.0, which is a broad range, but a four-year gap in a networking library is a real risk: TLS behavior, cookie handling, and stdlib HTTP internals have all changed since then. Choose it for the session and middleware model, not because it is the safer default.
Timeouts, Concurrency, and Connection Reuse
Crystal’s concurrency model makes it easy to fire many requests at once, and easy to leak connections while doing it.
| |
Three rules keep this from turning into an outage:
- Always set both
connect_timeoutandread_timeout. Crest, Halite, and the stdlib all default to no timeout. A peer that accepts the TCP connection and then never responds will hold the fiber forever. - Bound the concurrency. Spawning 5,000 fibers each opening a socket will exhaust file descriptors long before it exhausts the CPU. Use a worker pool or a semaphore.
- Reuse clients for sequential work. One
HTTP::Clientinstance per sequential batch, not one per request, or you pay a TLS handshake every time.
If you want numbers for your own workload rather than someone else’s blog, measure it:
| |
Run that against your actual endpoint, from your actual network. Published microbenchmarks rarely survive contact with a real TLS terminator and a real CDN.
Deployment: Static Binaries and Health Checks
Crystal compiles to a single binary, which makes container images pleasantly small. A multi-stage build with shards cached separately:
| |
The ca-certificates line is not optional. A static Crystal binary in a bare Alpine image will fail every HTTPS request with a certificate verification error, which looks like a network problem and is actually a missing trust store.
For health checks, probe the dependency rather than the process:
| |
A healthcheck subcommand that performs one real request with a 2-second connect timeout tells you whether the upstream is reachable. A TCP check tells you the container is running, which you already knew.
Pitfalls That Cost Real Debugging Time
- No default timeouts anywhere. Not in the stdlib, not in Crest, not in Halite. Set them explicitly on every call path.
- The stdlib ignores redirects. A 301 returns an empty body and a status code you probably are not checking.
HTTP::Clientinstances are not meant to be shared across fibers for concurrent requests. Use one client per fiber, or serialize access.- Relative
Locationheaders break naive redirect handling. Let Crest do it. - Missing
ca-certificatesin slim images producesSSL_connect: certificate verify failed, which reads like a TLS bug and is a packaging bug. - Halite’s age. If you adopt it, pin the version, and be prepared to vendor a patch if a future Crystal release changes stdlib HTTP semantics.
- Response body size.
response.bodyreads everything into memory. For exports and large JSON payloads, stream withbody_io.
Where This Fits in a Crystal Service
HTTP client choice looks trivial until you have ten integrations. At that point the difference between “raises on 500” and “returns a response you forgot to check” is the difference between an alert and a silent data gap. Crest’s defaults are the ones you want for anything external; the stdlib is the right tool when the call is internal, simple, and fully under your control.
Related reading: our Crystal web frameworks comparison covers the server side of the same stack, the Crystal database libraries guide shows how to persist what your client fetches, and the Crystal testing frameworks comparison explains how to stub these HTTP calls in specs instead of hitting a live API.

FAQ
Does Crystal’s stdlib HTTP client follow redirects automatically?
No. HTTP::Client.get returns the 3xx response as-is, including an empty body. You must read the Location header and issue a follow-up request yourself, taking care to preserve the method for 307 and 308 and to resolve relative locations. Crest handles all of this by default with max_redirects set to 10.
Does HTTP::Client raise an exception on a 500 response?
No. The stdlib client returns a response object for every HTTP status, including 4xx and 5xx. You are responsible for checking status_code. Crest raises Crest::RequestFailed by default and includes the response; set handle_errors: false when an error status is an expected branch.
Is Halite still maintained in 2026?
The newest release is 0.12.1 from 2022, and the repository’s last commit was in March 2022. It still compiles against current Crystal versions in most setups, but it is not actively developed. Use it only if you specifically need its session object or middleware features, and pin the version.
How do I set a timeout in Crystal HTTP clients?
Pass them explicitly. With Crest use connect_timeout: and read_timeout: (for example 2.seconds and 10.seconds). Halite accepts a timeout: {connect: 2.seconds, read: 10.seconds} hash. With the stdlib, set client.read_timeout = 10.seconds and client.connect_timeout = 2.seconds on the client instance. None of the three sets a default.
Which client should I use for many concurrent requests?
Use Crest or the stdlib with one client per fiber and a bounded worker pool. Do not share a single HTTP::Client across fibers issuing concurrent requests, and always bound concurrency so you do not exhaust file descriptors. Cache and reuse clients for sequential batches to avoid repeated TLS handshakes.
Why do HTTPS requests fail in my minimal Docker image?
Almost always a missing trust store. Install ca-certificates in the runtime image. Crystal binaries compiled with --static do not bundle a CA bundle, so certificate verification fails even though DNS and routing are fine.
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com