rembrembdocs

Skip to main content

Bun home pagelight logodark logo

[Runtime

](../../../index.md)[Package Manager

](../../../pm/cli/install/index.md)[Bundler

](../../../bundler/index.md)[Test Runner

](../../../test/index.md)[Guides

](../../index.md)[Reference

](https://bun.com/reference)[Blog

](https://bun.com/blog)[Feedback

](../../../feedback/index.md)

In Bun, the unix option in fetch() lets you send HTTP requests over a unix domain socket.

https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bfetch-unix.ts

const unix = "/var/run/docker.sock";

const response = await fetch("http://localhost/info", { unix });

const body = await response.json();
console.log(body); // { ... }

The unix option is a string that specifies the local file path to a unix domain socket. The fetch() function will use the socket to send the request to the server instead of using a TCP network connection. https is also supported by using the https:// protocol in the URL instead of http://. To send a POST request to an API endpoint over a unix domain socket:

https://mintcdn.com/bun-1dd33a4e/JUhaF6Mf68z_zHyy/icons/typescript.svg?fit=max&auto=format&n=JUhaF6Mf68z_zHyy&q=85&s=7ac549adaea8d5487d8fbd58cc3ea35bfetch-unix.ts

const response = await fetch("https://hostname/a/path", {
  unix: "/var/run/path/to/unix.sock",
  method: "POST",
  body: JSON.stringify({ message: "Hello from Bun!" }),
  headers: {
    "Content-Type": "application/json",
  },
});

const body = await response.json();

Was this page helpful?

Suggest editsRaise issue

[

Upload files via HTTP using FormData

Previous

](../file-uploads/index.md)[

Streaming HTTP Server with Async Iterators

Next

](../stream-iterator/index.md)