Search

Dark theme | Light theme

April 26, 2025

Nushell Niceties: Using Request Headers With HTTP Commands

The nice thing about the http command in Nushell is that you can interact with HTTP endpoints without the need to install any external tools. You can use several subcommands like get, post, put, delete and patch. Each of these commands has the options to specify request headers. You can use the option --headers or the short version -H followed by a list of header keys and values.

In the following example you can see how to use the --headers option to specify the request headers:

# Use the --headers option to specify the request headers.
# The headers are specified as a list of header keys and values.
http get --headers [Accept application/json] https://httpbin.org/headers

Instead of specifying the headers in the command you can also create a variable with list of header keys and values:

# Create a variable with a list of header keys and values.
const headers = [
    Accept application/json
    Origin https://mrhaki.com
    Access-Control-Request-Method GET
    Access-Control-Request-Headers content-type
]

# Use the variable with the http get command.
# In this case the short version -H is used.
http get -H $headers https://httpbin.org/headers

Written with Nushell 0.103.0.