Home Explore Blog CI



nushell

2nd chunk of `cookbook/http.md`
09b1e0621e8891f0161c51671d5608239240ac8ab188872e0000000100001715
# =>    │        │    │                                                         │ 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 }
# => ━━━┯━━━━━━━━┯━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# =>  # │ 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
# => ━━━┷━━━━━━━━┷━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

---

If you specify the `--raw` flag, you'll see 3 separate json objects, one in each row.

```nu
open urls.json | get urls | each { |u| http get $u -r }
# => ━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# =>  # │ <value>
# => ───┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# =>  0 │ {
# =>    │   "userId": 1,
# =>    │   "id": 1,
# =>    │   "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
# =>    │   "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum
# =>    │ rerum est autem sunt rem eveniet architecto"
# =>    │ }
# =>  1 │ {
# =>    │   "userId": 1,
# =>    │   "id": 2,
# =>    │   "title": "qui est esse",
# =>    │   "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro

Title: Fetching Multiple URLs with the `--raw` Flag in Nushell
Summary
This section explains how to fetch data from multiple URLs and display the responses as separate JSON objects using the `--raw` flag with the `http get` command in Nushell. It demonstrates how each URL's response is presented as an individual row in the output.