sveltekit-fetch-demo

Sveltekit Fetch Demo

Shows a very simple example of how to fetch data from an external REST API using SvelteKit

Fetch from a REST API in SvelteKit

This repo is a simple example of how to fetch data from a REST API using a SvelteKit app. You can use this as an example to follow when writing your own code.

The main things to note are in the +page.svelte file that gets rendered in the browser, and in the +page.server.js file that runs server-side.

Those files live side-by-side in the /src/routes/ directory, which means they're siblings and can communicate together in special SvelteKit ways.

You can do the same thing with a +layout.svelte and a +layout.server.js if you want the data to be available to any page that uses the layout.

You're basically doing the fetch part on the server and passing the resulting data to the page to display it.

Official documentation https://kit.svelte.dev/docs/load


Original README:

create-svelte

Everything you need to build a Svelte project, powered by create-svelte.

Creating a project

If you're seeing this, you've probably already done this step. Congrats!

# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app

Developing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Building

To create a production version of your app:

npm run build

You can preview the production build with npm run preview.

To deploy your app, you may need to install an adapter for your target environment.

Top categories

Loading Svelte Themes