Book Image

SvelteKit Up and Running

By : Dylan Hildenbrand
Book Image

SvelteKit Up and Running

By: Dylan Hildenbrand

Overview of this book

The JavaScript ecosystem has grown vast, complex, and daunting for newcomers. Fortunately, SvelteKit has emerged, simplifying the process of building JavaScript-based web applications. This book aims to demystify SvelteKit, making it as approachable as it makes web app development. With SvelteKit Up and Running you’ll be introduced to the philosophy and technologies underlying SvelteKit. First, you’ll follow a standard educational programming approach, progressing to a 'Hello World' application. Next, you’ll explore the fundamental routing techniques, data loading management, and user submission, all through real-world scenarios commonly encountered in day-to-day development, before discovering various adapters employed by SvelteKit to seamlessly integrate with diverse environments. You’ll also delve into advanced concepts like dynamic route management, error handling, and leveraging SvelteKit to optimize SEO and accessibility. By the end of this book, you’ll have mastered SvelteKit and will be well-equipped to navigate the complexities of web app development.
Table of Contents (19 chapters)
1
Part 1 – Getting Started with SvelteKit
5
Part 2 – Core Concepts
10
Part 3 – Supplemental Concepts

Destructuring RequestEvent

When it comes to load(), the server seems to have more information available to it than the client does. With so much data, it can be hard to know exactly all the information that is available. In short, server load() functions are called with a SvelteKit-specific RequestEvent. Here’s a quick breakdown of the properties (prop) and functions (fn) available from that object:

  • cookies (prop) – The cookies sent during the request.
  • fetch (fn) – A compatible variant of the Web API fetch() function discussed in Chapter 3. It comes with the added benefit of allowing requests based on relative routes as well as passing cookies and headers through when on the same server.
  • getClientAddress (fn) – Returns the client’s IP address.
  • locals (prop) – Any custom data inserted into the request via SvelteKit’s handle() hook. We’ll cover that in a later chapter.
  • params (prop) – Parameters specific...