Networking#

Nushell ships HTTP as a first-class built-in. http get, http post, http put, http delete, http patch, and http head cover the everyday cases; responses come back as structured records the operator can select and where without an external parser. For the rest (DNS, TCP probes, SSH, file transfer) Nu falls back to the same coreutils + network toolkit the rest of the shells use.

HTTP#

The defining built-in. No curl, no jq.

http get https://api.example.com/users/1
http get https://api.github.com/repos/nushell/nushell
    | select stargazers_count forks_count language

http post https://api.example.com/items {name: "operator"}
http post https://api.example.com/items {name: "operator"} -H {Authorization: "Bearer ..."}

http get --full https://example.com/                # returns headers + body
http head https://example.com/

Common flags worth memorizing.

  • --user / --password, basic auth.

  • --headers / -H, custom headers (record literal).

  • --content-type, body MIME type.

  • --max-time, --connect-timeout, always set in scripts.

  • --full, return the full response (status, headers, body) as a record instead of just the body.

  • --insecure / -k, skip TLS verification (use sparingly).

JSON#

JSON parsing is built into http and open.

http get https://api.example.com/users/1 | get name

open data.json | where age > 30 | select name email

{name: "operator"} | to json | save payload.json

URL#

The url namespace parses and assembles URLs without regex gymnastics.

"https://user:pass@example.com:443/path?q=1#frag" | url parse
╭───────────────┬──────────────────╮
│ scheme        │ https            │
│ username      │ user             │
│ password      │ pass             │
│ host          │ example.com      │
│ port          │ 443              │
│ path          │ /path            │
│ query         │ q=1              │
│ params        │ {record 1 field} │
│ fragment      │ frag             │
╰───────────────┴──────────────────╯

Round-trip with url join.

{scheme: "https", host: "example.com", path: "/v1/items"}
    | url join

TCP / UDP#

Nu has no built-in raw socket. Fall back to bash-style pseudo- paths through an external program or to nc.

^bash -c 'if (echo > /dev/tcp/host/22) 2>/dev/null; then echo open; fi'

^nc -zv host 22
^nc -u -zv host 53
^nc -l -p 4444

DNS#

External tools. Nu does not parse the output natively; lines or str trim cleans it up.

^dig +short example.com | lines
^dig +short example.com AAAA | lines
^getent hosts example.com

SSH and File Transfer#

External; same workflows as bash.

^ssh user@host "systemctl status nginx"
^scp file user@host:/path/
^rsync -aP src/ user@host:/path/

Fan out across a list with par-each.

[web01 db01 cache01] | par-each { |h|
    ^ssh -o ConnectTimeout=3 $h "uptime" | str trim
}

Authentication Tokens#

Don’t put tokens on the command line. Read from a file or $env.

let token = (open ~/.config/myapp/token | str trim)
http get https://api.example.com -H {Authorization: $"Bearer ($token)"}

http get https://api.example.com -H {Authorization: $"Bearer ($env.API_TOKEN)"}

Diagnostics#

External tools through ^.

^ping -c 3 host
^traceroute host
^mtr host
^ss -tulpn
^tcpdump -ni any port 443

For “is this URL up and how fast does it answer”.

let start = (date now)
let r = (http get --full https://example.com/)
let elapsed = ((date now) - $start)
{status: $r.status, time: $elapsed}

References#