Skip to content

Is fetch API planned to support unix domain socket? #2970

Open

Description

@JerrysShan

Many Node.js applications leverage Unix Domain Sockets for inter-process communication (IPC), providing a more efficient and secure way to communicate compared to traditional network sockets. Supporting the socketPath option in undici's fetch API could significantly benefit applications that rely on IPC, especially those dealing with microservices or local server communication.

it would be incredibly useful to have fetch requests directed to a Unix Domain Socket. This could look something like:

const response = await fetch('unix:///path/to/socket.sock/request-path', {
  method: 'GET'
  // additional options
});

Activity

  1. ronag commented on Mar 18, 2024

    @ronag
    Member

    Unlikely. We are only doing web spec stuff. If you are doing backend development why are you using fetch? Use undici.request and then you can use unix sockets.

  2. JerrysShan commented on Mar 18, 2024

    @JerrysShan
    Author

    Unlikely. We are only doing web spec stuff. If you are doing backend development why are you using fetch? Use undici.request and then you can use unix sockets.

    Because the fetch API is familiar to most developers, we also use the same API as the web on the server side.

  3. mcollina commented on Mar 18, 2024

    @mcollina
    SponsorMember

    I think supporting this should be easy enough and possibly just having the request pass the validation check.

    @KhafraDev wdyt?

  4. KhafraDev commented on Mar 18, 2024

    @KhafraDev
    Member

    I'm not opposed to it, as long as it doesn't add an option to fetch

  5. KhafraDev commented on Mar 20, 2024

    @KhafraDev
    Member

    in the meantime, you can use Agent with fetch

    import { fetch, Agent } from 'undici'
    
    const resp = await fetch('http://localhost/version', {
      dispatcher: new Agent({
        connect: {
          socketPath: '/var/run/docker.sock'
        }
      })
    })
    
    console.log(await resp.text())

    as a sidenote this is actually how people seem to fetch unix sockets in deno

  6. Radiergummi commented on Sep 8, 2024

    @Radiergummi

    If adding an option to fetch is problematic for some reason, how about just handling requests to unix:// in Deno itself, forwarding the request to the socket? To avoid name resolution/SNI issues, users could include an explicit Host header with their request that would need to be evaluated prior to dispatching.
    I know this isn't really elegant from the implementation perspective, but it'd solve the problem now without any API changes necessary, and works just like people would expect it to.

  7. Bacto commented on Sep 9, 2025

    @Bacto

    Hi,

    I'm surprised (and disapointed) that undici doesn't support, in an easy way, unix sockets.
    As suggested by @JerrysShan, having the ability to use fetch('unix://...') would be really great, pretty simple to implement and easy to use. It would also avoid to add undici as an external dependency.
    This is something I would expect from Node.js fetch implementation.

    Hope we could see that one day.

    Adrien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions