Oh man, I ran into the same issue last week! The whole localhost thing feels like a weird hack, but yeah, that’s just how curl how to specify path when using a socket works.
If you’re tired of guessing, check out httpie—it’s a bit more intuitive for unix sockets.
Command looks like:
`http --unix-socket /tmp/socket.sock localhost/path`
Way cleaner, imo.
Wait, really? localhost is mandatory? That’s so bizarre.
I’ve been using socat as a workaround when curl how to specify path when using a socket gets finicky. It’s not as direct, but it gives you more control.
Example:
`socat - UNIX-CONNECT:/tmp/socket.sock`
Then you can manually send HTTP requests. Clunky, but educational!
Yep, the localhost quirk is a head-scratcher. Found this in the curl docs—apparently it’s a legacy thing.
For debugging, try `-v` flag to see what’s actually being sent. Helped me spot why my curl how to specify path when using a socket was failing.
Also, Postman now supports unix sockets (beta feature). Might be worth a shot if you’re GUI-inclined.
Ugh, sockets are such a pain.
Pro tip: If you’re scripting this, wrap it in a function so you don’t have to remember the syntax.
```bash
sockcurl() {
curl --unix-socket /tmp/socket.sock "http://localhost$1"
}
```
Now just `sockcurl /path` and forget the weirdness.
Fun fact: This isn’t just a curl thing. Other tools like wget have similar quirks with unix sockets.
For curl how to specify path when using a socket, the hostname is basically ignored, but the field must exist. Dumb, but consistent?
If you’re on macOS, double-check socket paths—they’re case-sensitive there for some reason.
OP here—wow, didn’t expect so many workarounds!
The function wrapper idea is gold, gonna steal that.
Still baffled why the syntax is so janky though. Anyone know if there’s a *reason* localhost is required? Like, is some RFC to blame?
(Also tried httpie—huge improvement. Thanks for the tip!)
Alternative take: Skip curl and use nc (netcat) for raw socket fun.
```
printf "GET /path HTTP/1.1\r\nHost: localhost\r\n\r\n" | nc -U /tmp/socket.sock
```
Not as slick, but zero ambiguity about paths.
The curl maintainers actually debated changing this in 2019! Thread here: [GitHub link]. Consensus was "too late to fix without breaking things."
For curl how to specify path when using a socket, your best bet is aliases or wrapper scripts. Or switch to a HTTP client lib in your favorite language.
LOL welcome to the "why does curl do this" club.
Protip: If you omit the leading slash in the path, it fails silently. Took me HOURS to figure that out.
`http://localhostpath` ❌
`http://localhost/path` ✅
The devil’s in the details.