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

Hooks and Error Handling

While it can be incredibly useful to make API requests from any page, imagine the nuisance of attempting to authenticate a user for an external API on every page. It may be possible to create a custom helper that adds specific headers or cookies to every single request to assist with this. Fortunately for us, SvelteKit provides methods to manipulate Request and Response objects across the entirety of a framework. It does so with what are called hooks. These hooks can be incredibly powerful to manage data that flows in and out of our application. They can also be helpful for managing errors. Since our previous encounters with error handling have been so brief, we’ll examine error handling a little closer after covering hooks.

In this chapter, we will cover the following topics:

  • Using Hooks
  • Error Handling

As a practical example, we’ll build a simple interface allowing us to star the official SvelteKit repository on GitHub....