Fetch
To begin, let’s take a look at one of the most commonly used Web APIs, fetch
. Assuming your development environment is on the latest LTS version of Node.js (v18+), you’ll have access to fetch
on the server without having to install an extra package such as node-fetch
. That package was the most widely used package to deliver functionality, allowing developers to make network requests before fetch
was incorporated into Node.js's core features. Since fetch
is now also supported in every major browser, we can safely use it in both client- and server-side environments to make external and internal requests. Because SvelteKit can run in both a browser and server environment, it is safe to say that we have, in fact, “made fetch happen.”
To illustrate how fetch can work in both the browser and server, let’s take a look at an example. We’ll create a new route by adding the src/routes/fetch/+page.svelte
file to serve as our demo page. We...