Home Explore Blog CI



nushell

1st chunk of `cookbook/http.md`
2ea96590b67d3ffa2f3b4ea35443dd9cfca434d7d45e311f00000001000014ab
---
title: HTTP
---

# HTTP

### Fetching JSON from a url

```nu
http get https://jsonplaceholder.typicode.com/posts | first 5
# => ━━━┯━━━━━━━━┯━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# =>  # │ userId │ id │ title                                                   │ body
# => ───┼────────┼────┼─────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────
# =>  0 │      1 │  1 │ sunt aut facere repellat provident occaecati excepturi  │ quia et suscipit
# =>    │        │    │ optio reprehenderit                                     │ suscipit recusandae consequuntur expedita et cum
# =>    │        │    │                                                         │ reprehenderit molestiae ut ut quas totam
# =>    │        │    │                                                         │ nostrum rerum est autem sunt rem eveniet architecto
# =>  1 │      1 │  2 │ qui est esse                                            │ est rerum tempore vitae
# =>    │        │    │                                                         │ sequi sint nihil reprehenderit dolor beatae ea dolores
# =>    │        │    │                                                         │ neque
# =>    │        │    │                                                         │ fugiat blanditiis voluptate porro vel nihil molestiae ut
# =>    │        │    │                                                         │ reiciendis
# =>    │        │    │                                                         │ qui aperiam non debitis possimus qui neque nisi nulla
# =>  2 │      1 │  3 │ ea molestias quasi exercitationem repellat qui ipsa sit │ et iusto sed quo iure
# =>    │        │    │ aut                                                     │ voluptatem occaecati omnis eligendi aut ad
# =>    │        │    │                                                         │ voluptatem doloribus vel accusantium quis pariatur
# =>    │        │    │                                                         │ molestiae porro eius odio et labore et velit aut
# =>  3 │      1 │  4 │ eum et est occaecati                                    │ ullam et saepe reiciendis voluptatem adipisci
# =>    │        │    │                                                         │ sit amet autem assumenda provident rerum culpa
# =>    │        │    │                                                         │ quis hic commodi nesciunt rem tenetur doloremque ipsam
# =>    │        │    │                                                         │ iure
# =>    │        │    │                                                         │ quis sunt voluptatem rerum illo velit
# =>  4 │      1 │  5 │ nesciunt quas odio                                      │ repudiandae veniam quaerat sunt sed
# =>    │        │    │                                                         │ alias aut fugiat sit autem sed est
# =>    │        │    │                                                         │ voluptatem omnis possimus esse voluptatibus quis
# =>    │        │    │                                                         │ est aut tenetur dolor neque
# => ━━━┷━━━━━━━━┷━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

---

### Fetch from multiple urls

Suppose you are querying several endpoints,
perhaps with different query parameters and you want to view all the responses as a single dataset.

An example JSON file, `urls.json`, with the following contents:

```json
{
  "urls": [
    "https://jsonplaceholder.typicode.com/posts/1",
    "https://jsonplaceholder.typicode.com/posts/2",
    "https://jsonplaceholder.typicode.com/posts/3"
  ]
}
```

```nu
open urls.json | get urls | each { |u| http get $u }
# => ━━━┯━━━━━━━━┯━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Title: Fetching Data with HTTP in Nushell
Summary
This section demonstrates how to fetch JSON data from URLs using the `http get` command in Nushell. It includes examples of fetching data from a single URL and fetching data from multiple URLs listed in a JSON file.