Skip to content

Commit eac7433

Browse files
committed
updated code example and added to sidebar
1 parent 90e56ea commit eac7433

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

apps/site/navigation.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@
185185
"link": "/learn/getting-started/profiling",
186186
"label": "components.navigation.learn.gettingStarted.links.profiling"
187187
},
188+
"fetch": {
189+
"link": "/learn/getting-started/fetch",
190+
"label": "components.navigation.learn.gettingStarted.links.fetch"
191+
},
188192
"securityBestPractices": {
189193
"link": "/learn/getting-started/security-best-practices",
190194
"label": "components.navigation.learn.gettingStarted.links.securityBestPractices"

apps/site/pages/en/learn/client-networking/fetch.md renamed to apps/site/pages/en/learn/getting-started/fetch.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@ authors: benhalverson, LankyMoose
88

99
## Introduction
1010

11-
In this guide, we will learn how to use the Fetch API with Undici in Node.js. The Fetch API is a modern interface that allows you to make HTTP requests in the browser. It is similar to the XMLHttpRequest object, but with a more powerful and flexible feature set. Undici is a high-performance HTTP/1.1 client that is designed to be used with Node.js. It is built on top of the HTTP/1.1 parser from Node.js core, and it provides a simple and efficient API for making HTTP requests.
12-
13-
## Why use Undici?
14-
15-
[Undici](https://undici.nodejs.org) is a high-performance HTTP client for Node.js. While Node.js 18+ ships with a built-in Fetch API.
11+
[Unidici](httpss://undici.nodejs.org) is an HTTP client libary that powers the fetch API in Node.js. It was written from scratch and does not rely on the built-in HTTP client in Node.js. It includes a number of features that make it a good choice for high-performance applications.
1612

1713
```mjs
18-
import { fetch } from 'undici';
19-
2014
async function main() {
2115
const response = await fetch('https://jsonplaceholder.typicode.com/posts');
2216
const data = await response.json();
@@ -30,6 +24,8 @@ main().catch(console.error);
3024

3125
Undici allows you to customize the Fetch API by providing options to the `fetch` function. For example, you can set custom headers, set the request method, and set the request body. Here is an example of how you can customize the Fetch API with Undici:
3226

27+
With a pool, you can reuse connections to the same server, which can improve performance. Here is an example of how you can use a pool with Undici:
28+
3329
```mjs
3430
import { Pool } from 'undici';
3531

packages/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"nodejsWithWebassembly": "Node.js with WebAssembly",
4343
"debugging": "Debugging Node.js",
4444
"profiling": "Profiling Node.js Applications",
45+
"fetch": "Fetching data with Node.js",
4546
"securityBestPractices": "Security Best Practices"
4647
}
4748
},

0 commit comments

Comments
 (0)